Module: Pickle::Path

Defined in:
lib/pickle/path.rb

Instance Method Summary collapse

Instance Method Details

#path_to_pickle(*pickle_names) ⇒ Object

given args of pickle model name, and an optional extra action, or segment, will attempt to find a matching named route

path_to_pickle 'the user', :action => 'edit'       # => /users/3/edit
path_to_pickle 'the user', 'the comment'           # => /users/3/comments/1
path_to_pickle 'the user', :segment => 'comments'  # => /users/3/comments

If you don;t know if the ‘extra’ part of the path is an action or a segment, then just pass it as ‘extra’ and this method will run through the possibilities

path_to_pickle 'the user', :extra => 'new comment' # => /users/3/comments/new


14
15
16
17
18
19
20
21
22
23
# File 'lib/pickle/path.rb', line 14

def path_to_pickle(*pickle_names)
  options = pickle_names.extract_options!
  resources = pickle_names.map{|n| model(n) || n.to_sym}
  if options[:extra]
    parts = options[:extra].underscore.gsub(' ','_').split("_")
    find_pickle_path_using_action_segment_combinations(resources, parts)
  else
    pickle_path_for_resources_action_segment(resources, options[:action], options[:segment])
  end or raise "Could not figure out a path for #{pickle_names.inspect} #{options.inspect}"
end