From fadaba679ac81aaab5c035bce61a369c1b33b1fe Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 2 Feb 2008 05:57:16 +0000 Subject: Introduce map.resources :cards, :as => 'tarjetas' to use a custom resource name in the URL: cards_path == '/tarjetas'. Closes #10578. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8785 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/resources.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/resources.rb') diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 8ec6b84a53..52173bc8bb 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -44,13 +44,14 @@ module ActionController module Resources class Resource #:nodoc: attr_reader :collection_methods, :member_methods, :new_methods - attr_reader :path_prefix, :name_prefix + attr_reader :path_prefix, :name_prefix, :path_segment attr_reader :plural, :singular attr_reader :options def initialize(entities, options) @plural ||= entities @singular ||= options[:singular] || plural.to_s.singularize + @path_segment = options.delete(:as) || @plural @options = options @@ -75,7 +76,7 @@ module ActionController end def path - @path ||= "#{path_prefix}/#{plural}" + @path ||= "#{path_prefix}/#{path_segment}" end def new_path @@ -236,6 +237,13 @@ module ActionController # * :singular - specify the singular name used in the member routes. # * :requirements - set custom routing parameter requirements. # * :conditions - specify custom routing recognition conditions. Resources sets the :method value for the method-specific routes. + # * :as - specify a different resource name to use in the URL path. For example: + # # products_path == '/productos' + # map.resources :products, :as => 'productos' do |product| + # # product_reviews_path(product) == '/productos/1234/comentarios' + # product.resources :product_reviews, :as => 'comentarios' + # end + # # * :path_prefix - set a prefix to the routes with required route variables. # # Weblog comments usually belong to a post, so you might use resources like: -- cgit v1.2.3