I have an app where I have to be able to add records to a table if the
parent record has a boolean field value of 0. Otherwise it should be
impossible to add new records that belong_to that record.
start with the permissions on the child model. create_permitted? should check that the parent is set and the value is appropriate.
Then you probably want the new/create action to be an owned action instead of standard so that the parent is properly set.
Aside: I prefer to think of booleans in true/false. DB storage varies, in ruby truth is not nil or false. Anything else is true
end
def update_permitted?
acting_user.administrator?
end
def destroy_permitted?
acting_user.administrator?
end
def view_permitted?(field)
true
end
end
Then you probably want the new/create action to be an owned action instead of standard so that the parent is properly set.
class ZeroAccountsController < ApplicationController
hobo_model_controller
auto_actions :all
auto_actions_for :one_acount, [:new, :create]
end
Aside: I prefer to think of booleans in true/false. DB storage varies, in ruby truth is not nil or false. Anything else is true
Is my reasoning along those guidelines?
--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
This is what I have now. Is this a bad setup?
class OneAccount < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
# balance :integer, :default => 0
transactional :boolean, :default => false
timestamps
end
belongs_to :zero_account
has_many :two_accounts, :dependent => :destroy, :accessible => true
children :two_accounts
# --- Permissions --- #
def create_permitted?
!zero_account.transactional?
end
class ZeroAccount < ActiveRecord::Base
end
class OneAccountsController < ApplicationController
hobo_model_controller
auto_actions :all, :except => :index
auto_actions_for :zero_account, [:new, :create]
end
class ZeroAccountsController < ApplicationController
hobo_model_controller
auto_actions :all
end
The problem is that zero_account.transactional must not be checked if I
want inline new child create_new. Your input is thankfully received.
Thanks. I will upload the app and share it with an AGLP v3 license.