| Module | ResourceController::Helpers::Nested |
| In: |
../lib/resource_controller/helpers/nested.rb
|
If there is a parent, returns the relevant association proxy. Otherwise returns model.
# File ../lib/resource_controller/helpers/nested.rb, line 62
62: def end_of_association_chain
63: parent? ? parent_association : model
64: end
Returns true/false based on whether or not a parent is present.
# File ../lib/resource_controller/helpers/nested.rb, line 33
33: def parent?
34: !parent_type.nil?
35: end
Returns the relevant association proxy of the parent. (i.e. /posts/1/comments # => @post.comments)
# File ../lib/resource_controller/helpers/nested.rb, line 9
9: def parent_association
10: @parent_association ||= parent_object.send(model_name.to_s.pluralize.to_sym)
11: end
Like the model method, but for a parent relationship.
# File ../lib/resource_controller/helpers/nested.rb, line 50
50: def parent_model
51: parent_type.to_s.camelize.constantize
52: end
Returns the current parent object if a parent object is present.
# File ../lib/resource_controller/helpers/nested.rb, line 56
56: def parent_object
57: parent? && !parent_singleton? ? parent_model.find(parent_param) : nil
58: end
Returns the current parent param, if there is a parent. (i.e. params[:post_id])
# File ../lib/resource_controller/helpers/nested.rb, line 44
44: def parent_param
45: params["#{parent_type}_id".to_sym]
46: end
Returns true/false based on whether or not a parent is a singleton.
# File ../lib/resource_controller/helpers/nested.rb, line 39
39: def parent_singleton?
40: !parent_type_from_request.nil? && parent_type_from_params.nil?
41: end
Returns the type of the current parent
# File ../lib/resource_controller/helpers/nested.rb, line 15
15: def parent_type
16: @parent_type ||= parent_type_from_params || parent_type_from_request
17: end
Returns the type of the current parent extracted from params
# File ../lib/resource_controller/helpers/nested.rb, line 21
21: def parent_type_from_params
22: [*belongs_to].find { |parent| !params["#{parent}_id".to_sym].nil? }
23: end