You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we often use the pattern of scoping all of our controllers by objects that are not explicitly set as parents. This is a bit like the begin_of_association_chain method in inherited_resources (found: http://github.com/josevalim/inherited_resources/tree/master ).
a quick solution that we implemented is as follows:
in nested.rb
module ResourceController
module Helpers
module Nested
protected
....
def scoped?
scoping_object.present?
end
def scope_association
@scope_association ||= scoping_object.send(model_name.to_s.pluralize.to_sym)
end
def end_of_association_chain
return scope_association if scoped?
parent? ? parent_association : model
end
...
end
and then in the controller it is used as follows:
def scoping_object
current_facility
end
This will scope all finds using current_facility.associations.find and create using
current_facility.associations.new
The text was updated successfully, but these errors were encountered:
we often use the pattern of scoping all of our controllers by objects that are not explicitly set as parents. This is a bit like the begin_of_association_chain method in inherited_resources (found: http://github.com/josevalim/inherited_resources/tree/master ).
a quick solution that we implemented is as follows:
in nested.rb
and then in the controller it is used as follows:
This will scope all finds using current_facility.associations.find and create using
current_facility.associations.new
The text was updated successfully, but these errors were encountered: