public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Allow alternative values for the 'new' and 'edit' actions in resourceful 
routes.

map.resource :schools, :as => 'escuelas', :path_names => { :new 
=> 'nueva' }

Closes #11181.  [ivanvr]
NZKoz (author)
Fri Apr 11 17:40:40 -0700 2008
commit  063c393bf0a2eb762770c97f925b7c2867361ad4
tree    81eda9f330faa3cebbe1a77b19a68476cfc77eac
parent  4364c361b599f99bc2345ce4eb2d145b07ed8a0f
...
337
338
339
 
 
 
 
340
341
342
...
337
338
339
340
341
342
343
344
345
346
0
@@ -337,6 +337,10 @@
0
     @@resource_action_separator = "/"
0
     cattr_accessor :resource_action_separator
0
     
0
+ # Allow to override path names for default resources' actions
0
+ @@resources_path_names = { :new => 'new', :edit => 'edit' }
0
+ cattr_accessor :resources_path_names
0
+
0
     # Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default
0
     cattr_accessor :request_forgery_protection_token
0
 
...
80
81
82
83
 
 
 
84
85
86
...
266
267
268
 
 
 
 
 
 
 
269
270
271
...
515
516
517
518
519
 
 
 
 
 
 
 
 
520
521
522
...
80
81
82
 
83
84
85
86
87
88
...
268
269
270
271
272
273
274
275
276
277
278
279
280
...
524
525
526
 
 
527
528
529
530
531
532
533
534
535
536
537
0
@@ -80,7 +80,9 @@
0
       end
0
 
0
       def new_path
0
- @new_path ||= "#{path}/new"
0
+ new_action = self.options[:path_names][:new] if self.options[:path_names]
0
+ new_action ||= Base.resources_path_names[:new]
0
+ @new_path ||= "#{path}/#{new_action}"
0
       end
0
 
0
       def member_path
0
@@ -266,6 +268,13 @@
0
     # notes.resources :attachments
0
     # end
0
     #
0
+ # * <tt>:path_names</tt> - specify different names for the 'new' and 'edit' actions. For example:
0
+ # # new_products_path == '/productos/nuevo'
0
+ # map.resources :products, :as => 'productos', :path_names => { :new => 'nuevo', :edit => 'editar' }
0
+ #
0
+ # You can also set default action names from an environment, like this:
0
+ # config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' }
0
+ #
0
     # * <tt>:path_prefix</tt> - set a prefix to the routes with required route variables.
0
     #
0
     # Weblog comments usually belong to a post, so you might use resources like:
0
@@ -515,8 +524,14 @@
0
         resource.member_methods.each do |method, actions|
0
           actions.each do |action|
0
             action_options = action_options_for(action, resource, method)
0
- map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options)
0
- map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format",action_options)
0
+ action_path = action
0
+ if resource.options[:path_names]
0
+ action_path = resource.options[:path_names][action]
1
+ action_path ||= Base.resources_path_names[action]
0
+ end
0
+
0
+ map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
0
+ map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options)
0
           end
0
         end
0
 
...
76
77
78
 
 
 
 
 
 
79
80
81
...
76
77
78
79
80
81
82
83
84
85
86
87
0
@@ -76,6 +76,12 @@
0
     end
0
   end
0
 
0
+ def test_override_paths_for_default_restful_actions
0
+ resource = ActionController::Resources::Resource.new(:messages,
0
+ :path_names => {:new => 'nuevo', :edit => 'editar'})
0
+ assert_equal resource.new_path, "#{resource.path}/nuevo"
0
+ end
0
+
0
   def test_multiple_default_restful_routes
0
     with_restful_routing :messages, :comments do
0
       assert_simply_restful_for :messages

Comments