On 21/11/11 13:58, Quiliro Ordóñez wrote:
Thank you very much, Kevin. Please help me with my questions below.
On 18/11/11 16:01, kevinpfromnm wrote:
start with the permissions on the child model. create_permitted?
should check that the parent is set and the value is appropriate.
I have been trying to understand how to do this because I'm just
starting to understand the swign of Hobo. Here is my shot. Please confirm:
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
def update_permitted?
acting_user.administrator?
end
def destroy_permitted?
acting_user.administrator?
end
def view_permitted?(field)
true
end
end
class ZeroAccount < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
name :string
# balance :integer, :default => 0
transactional :boolean, :default => false
timestamps
end
has_many :one_accounts, :dependent => :destroy, :accessible => true
children :one_accounts
# --- Permissions --- #
def create_permitted?
acting_user.administrator?
This should change to:
def create_permitted?
zero_account.transactional?
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
<http://cookbook.hobocentral.net/manual/controllers#owner_actions>
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.