PiRSquared17 / activescaffold

Automatically exported from code.google.com/p/activescaffold
MIT License
0 stars 0 forks source link

Way to provide parent model id param with nested link. #752

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I want use create_authorized? update_authorized? and delete_authorized? 
methods in a controllers to remove action links for crud actions in such a 
way:
Test has_many :subtests.
In SubtestsController

def create_authorized?
  current_user == Test.find(params[:parent_id]).owner
end

It's to provide crud actions on subtest to owner of the Test (it's 
controller has a nested link to subtests). Is there any way to get parent_id 
or something in this way? 

Original issue reported on code.google.com by VoronkovAA@gmail.com on 2 Jun 2010 at 2:29

GoogleCodeExporter commented 9 years ago
In a nested scaffold, you can get the parent id in active_scaffold_constraints. 
If
your association in subtest is named parent, you have to use
active_scaffold_constraints[:parent].

If you can go to subtests controller without nesting, you should use something 
like
this:
def create_authorized?
  if active_scaffold_constraints[:parent]
    current_user == Test.find(active_scaffold_constraints[:parent]).owner
  else
    super
  end
end

For questions what aren't bugs or feature requests is better to use the google
group.

Original comment by sergio.c...@gmail.com on 2 Jun 2010 at 7:30