Hi All,
I've posted a question about this recently, but hopefully if I'm a bit more
specific, I'll get a response. I have a problem with ActiveScaffold
permissions being called before the actual record is instantiated. My
problem is that in my case, the permission to edit something must be
obtained from a belongs_to relationship on the model consider this scenario
Class Child < ActiveRecord::Base
belongs_to :parent
validates_presence_of :parent_id
def authorized_for_update?
current_user.permissions.include?(parent.create_permission)
end
end
Class Parent < ActiveRecord::Base
has_many :children
has_one :create_permission, :class_name => "Permission", :as =>
:approvable, :conditions => "name = 'Parent Creator'"
end
so, when I go to a url such as localhost:3000/children/3/edit , I get a nil
error on the call to parent inside of Child#authorized_for_update? even
though Child.find(3) returns a valid Child object. The reason is because
update_authorized_filter, the method which ultimately calls
:authorized_for_update? on the model, is called before the record is found,
so somewhere in the chain, a new Child record is being instantiated and the
permission method is being called against it. Am I experiencing a bug here?
or is this actually how this is supposed to work? If the latter is true, it
doesn't make much sense to me to put the authorization methods in the model
if the actual model object you're trying to work from isn't going be
available. for now, I've had to put a skip_before_filter
:update_authorized_filter on the offending controller and rewrite the
update_respond_to_html and edit_respond_to_html to get the proper
behaviour. Is there a better way to do this? Can we fix it so that @record
is found BEFORE we try to call security methods against it?
thx for your help,
-C
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.