module InheritedResources::PolymorphicHelpers
def parent
variable name: @task, @file, @note...
Returns the parent object. They are also available with the instance
def parent instance_variable_get("@#{@parent_type}") if @parent_type end
def parent?
If the polymorphic association is optional, we might not have a parent.
def parent? if resources_configuration[:polymorphic][:optional] parents_symbols.size > 1 || !@parent_type.nil? else true end end
def parent_class
def parent_class parent.class if @parent_type end
def parent_type
as parent types.
Returns the parent type. A Comments class can have :task, :file, :note
def parent_type @parent_type end
def symbols_for_association_chain #:nodoc:
params are missing.
When optional is given, it does not raise errors if the polymorphic
params keys to see which polymorphic parent matches the given params.
If the parents_symbols find :polymorphic, it goes through the
Maps parents_symbols to build association chain.
def symbols_for_association_chain #:nodoc: polymorphic_config = resources_configuration[:polymorphic] parents_symbols.map do |symbol| if symbol == :polymorphic params_keys = params.keys key = polymorphic_config[:symbols].find do |poly| params_keys.include? resources_configuration[poly][:param].to_s end if key.nil? raise ScriptError, "Could not find param for polymorphic association. The request" << "parameters are #{params.keys.inspect} and the polymorphic " << "associations are #{polymorphic_config[:symbols].inspect}." unless polymorphic_config[:optional] nil else @parent_type = key.to_sym end else symbol end end.compact end