Created
March 16, 2011 23:38
-
-
Save benders/873550 to your computer and use it in GitHub Desktop.
Hack to define helper named routes in Rails 2.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionController::Routing::Routes.draw do |map| | |
... | |
end | |
module CustomRoutes | |
protected | |
def incident_url( record, options = {} ) | |
account_application_alert_url(record.account_id, record.application_id, record.id, options) | |
end | |
def alerts_event_url( record, options = {} ) | |
account_event_url(record.account_id, record.id, options) | |
end | |
# Create foo_path methods that call foo_url with :routing_type => :path | |
protected_instance_methods.grep(/_url$/).each do |url_method| | |
path_method = url_method.sub(/_url$/, '_path') | |
module_eval %{ | |
def #{path_method}(record_or_hash_or_array, options = {}) | |
options[:routing_type] = :path | |
#{url_method}(record_or_hash_or_array, options) | |
end | |
} | |
end | |
end | |
class ActionController::Base | |
include ::CustomRoutes | |
end | |
class ActionView::Base | |
include ::CustomRoutes | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment