Module: ResourcefulParenting::ActionController::Base::InstanceMethods
- Defined in:
- lib/resourceful_parenting.rb
Instance Method Summary collapse
-
#parent(level = -1)) ⇒ Object
Returns a parent object extracted from a nested URL Takes an array index of depth (how far up parents to get) - defaults to -1 (most immediate) Returns nil if no such parent exists.
-
#parents ⇒ Object
Returns an array of parent objects.
-
#polymorphic_p_path(record_or_hash_or_array, options = {}) ⇒ Object
Analogous to Rails’ polymorphic_path, but add all parents to call.
-
#polymorphic_p_url(record_or_hash_or_array, options = {}) ⇒ Object
Analogous to Rails’ polymorphic_url, but add all parents to call.
Instance Method Details
#parent(level = -1)) ⇒ Object
Returns a parent object extracted from a nested URL Takes an array index of depth (how far up parents to get) - defaults to -1 (most immediate) Returns nil if no such parent exists
43 44 45 46 |
# File 'lib/resourceful_parenting.rb', line 43 def parent(level = -1) info = parse_parents[level] instance_from_parent_info(info) end |
#parents ⇒ Object
Returns an array of parent objects
32 33 34 35 36 |
# File 'lib/resourceful_parenting.rb', line 32 def parents parse_parents.map do |info| instance_from_parent_info(info) end end |
#polymorphic_p_path(record_or_hash_or_array, options = {}) ⇒ Object
Analogous to Rails’ polymorphic_path, but add all parents to call
25 26 27 |
# File 'lib/resourceful_parenting.rb', line 25 def polymorphic_p_path(record_or_hash_or_array, = {}) polymorphic_p_url(record_or_hash_or_array, .merge(:routing_type => :path)) end |
#polymorphic_p_url(record_or_hash_or_array, options = {}) ⇒ Object
Analogous to Rails’ polymorphic_url, but add all parents to call
16 17 18 19 20 |
# File 'lib/resourceful_parenting.rb', line 16 def polymorphic_p_url(record_or_hash_or_array, = {}) record_or_hash_or_array = [record_or_hash_or_array] unless record_or_hash_or_array.is_a?(Array) record_or_hash_or_array = parents + record_or_hash_or_array polymorphic_url(record_or_hash_or_array, ) end |