module InheritedResources::ShallowHelpers

Shallow provides a functionality that goes on pair with Rails’ shallow. It is very similar to “optional” but it actually finds all the parents resources instead of leaving them blank. Consider the following example:

belongs_to :post, :shallow => true do
  belongs_to :comment
end

When accessed as /comments/1, Inherited Resources will automatically get the post resource so both objects are actually accessible through the views.

However, when using optional, Inherited Resources wouldn’t actually bother with finding the parent object.

Private Instance Methods

load_parents(instance, parent_symbols) click to toggle source
# File lib/inherited_resources/shallow_helpers.rb, line 37
def load_parents(instance, parent_symbols)
  parent_symbols.reverse_each do |parent|
    instance = instance.send(parent)
    config   = resources_configuration[parent]
    params[config[:param]] = instance.to_param
  end
end