Skip to content

Instantly share code, notes, and snippets.

@aziz
Created November 11, 2010 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aziz/672843 to your computer and use it in GitHub Desktop.
Save aziz/672843 to your computer and use it in GitHub Desktop.
# 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