Ticket #11181: custom_paths_for_default_resource_actions.diff
| File custom_paths_for_default_resource_actions.diff, 3.0 kB (added by ivanvr, 2 years ago) |
|---|
-
test/controller/resources_test.rb
old new 76 76 end 77 77 end 78 78 79 def test_override_paths_for_default_restful_actions 80 resource = ActionController::Resources::Resource.new(:messages, 81 :path_names => {:new => 'nuevo', :edit => 'editar'}) 82 assert_equal resource.new_path, "#{resource.path}/nuevo" 83 end 84 79 85 def test_multiple_default_restful_routes 80 86 with_restful_routing :messages, :comments do 81 87 assert_simply_restful_for :messages -
lib/action_controller/base.rb
old new 340 340 @@resource_action_separator = "/" 341 341 cattr_accessor :resource_action_separator 342 342 343 # Allow to override path names for default resources' actions 344 @@resources_path_names = { :new => 'new', :edit => 'edit' } 345 cattr_accessor :resources_path_names 346 343 347 # Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default 344 348 cattr_accessor :request_forgery_protection_token 345 349 -
lib/action_controller/resources.rb
old new 80 80 end 81 81 82 82 def new_path 83 @new_path ||= "#{path}/new" 83 new_action = self.options[:path_names][:new] if self.options[:path_names] 84 new_action ||= Base.resources_path_names[:new] 85 @new_path ||= "#{path}/#{new_action}" 84 86 end 85 87 86 88 def member_path … … 493 495 resource.member_methods.each do |method, actions| 494 496 actions.each do |action| 495 497 action_options = action_options_for(action, resource, method) 496 map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options) 497 map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format",action_options) 498 action_path = action 499 if resource.options[:path_names] 500 action_path = resource.options[:path_names][action] 501 action_path ||= Base.resources_path_names[action] 502 end 503 504 map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options) 505 map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options) 498 506 end 499 507 end 500 508