Created
November 11, 2010 17:24
-
-
Save aziz/672843 to your computer and use it in GitHub Desktop.
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
# The following initializer provides an :alias => "my_route_name" option to restful routes in your | |
# route.rb. This simply makes the same route also available under a different …_path / …_url helpers. | |
# For example, | |
# map.resources :notes, :alias => :snippets | |
# Gives you | |
# notes_path, notes_url, new_note_path... #as always | |
# snippets_path, snippets_url, new_snippet_path... #from the alias | |
# Put this into an initializer: | |
module ActionController::Resources | |
def resources_with_alias(*args, &block) | |
name = args.first | |
options = args.last || {} | |
name_alias = options.delete(:alias) | |
resources_without_alias(*args, &block) | |
if name_alias | |
resources_without_alias(name_alias, options.merge(:controller => "#{options[:namespace]}#{name}", :as => name)) | |
end | |
end | |
alias_method_chain :resources, :alias | |
def resource_with_alias(*args, &block) | |
name = args.first | |
options = args.last || {} | |
name_alias = options.delete(:alias) | |
resource_without_alias(*args, &block) | |
if name_alias | |
resource_without_alias(name, options.merge(:controller => "#{options[:namespace]}#{name}", :as => name)) | |
end | |
end | |
alias_method_chain :resource, :alias | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment