Module: Resourcelogic::Urligence
- Included in:
- ActionController::Base
- Defined in:
- lib/resourcelogic/urligence.rb
Class Method Summary collapse
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
Dynamically generate url methods for better flexibility. This allows us to not only call the standard urls:
edit_object_path
object_path
but also be able to call custom method paths:
select_object_path
Where select is a method added yourself:
map.resources :users, :member => {:select => :any}
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/resourcelogic/urligence.rb', line 123 def method_missing(method, *args, &block) if method.to_s =~ /^((.*)_)?(child_collection|parent_collection|sibling|sibling_collection)_(path|url)$/ || method.to_s =~ /^((.*)_)?(child|collection|object|parent)_(path|url)$/ action = $2.blank? ? nil : $2.to_sym target = $3 url_type = $4 send("smart_#{url_type}", *send("#{target}_url_parts", action, *args)) else super end end |
Class Method Details
.included(klass) ⇒ Object
3 4 5 |
# File 'lib/resourcelogic/urligence.rb', line 3 def self.included(klass) klass.helper_method :smart_url, :smart_path, :method_missing end |
Instance Method Details
#smart_path(*url_parts) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/resourcelogic/urligence.rb', line 14 def smart_path(*url_parts) url_params = url_parts. url_parts.push(:path) url_parts.push(url_params) urligence(*url_parts) end |
#smart_url(*url_parts) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/resourcelogic/urligence.rb', line 7 def smart_url(*url_parts) url_params = url_parts. url_parts.push(:url) url_parts.push(url_params) urligence(*url_parts) end |