aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2008-04-12 10:26:29 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2008-04-12 10:26:29 -0500
commit342dcfe789d11e07f89d4ddfc3dc581da650a65e (patch)
tree766fd0cabb0090b7f85bfa5a809997cfaf3da9db /actionpack/lib/action_controller
parentb8bc92e61914cc6ef9d6ca12aba27d440ec0ebd5 (diff)
parent60be4b09f51d2560802ebd744893bb6f737ef57c (diff)
downloadrails-342dcfe789d11e07f89d4ddfc3dc581da650a65e.tar.gz
rails-342dcfe789d11e07f89d4ddfc3dc581da650a65e.tar.bz2
rails-342dcfe789d11e07f89d4ddfc3dc581da650a65e.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack/lib/action_controller')
-rwxr-xr-xactionpack/lib/action_controller/base.rb4
-rw-r--r--actionpack/lib/action_controller/components.rb13
-rw-r--r--actionpack/lib/action_controller/polymorphic_routes.rb12
-rw-r--r--actionpack/lib/action_controller/resources.rb21
4 files changed, 40 insertions, 10 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 7c838ba769..63ad4d042a 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -337,6 +337,10 @@ module ActionController #:nodoc:
@@resource_action_separator = "/"
cattr_accessor :resource_action_separator
+ # Allow to override path names for default resources' actions
+ @@resources_path_names = { :new => 'new', :edit => 'edit' }
+ cattr_accessor :resources_path_names
+
# Sets the token parameter name for RequestForgery. Calling #protect_from_forgery sets it to :authenticity_token by default
cattr_accessor :request_forgery_protection_token
diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb
index 7f7ecfff78..8275bd380a 100644
--- a/actionpack/lib/action_controller/components.rb
+++ b/actionpack/lib/action_controller/components.rb
@@ -39,12 +39,7 @@ module ActionController #:nodoc:
base.class_eval do
include InstanceMethods
extend ClassMethods
-
- helper do
- def render_component(options)
- @controller.send!(:render_component_as_string, options)
- end
- end
+ helper HelperMethods
# If this controller was instantiated to process a component request,
# +parent_controller+ points to the instantiator of this controller.
@@ -67,6 +62,12 @@ module ActionController #:nodoc:
end
end
+ module HelperMethods
+ def render_component(options)
+ @controller.send!(:render_component_as_string, options)
+ end
+ end
+
module InstanceMethods
# Extracts the action_name from the request parameters and performs that action.
def process_with_components(request, response, method = :perform_action, *arguments) #:nodoc:
diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb
index f043d89dae..2cc2ec7723 100644
--- a/actionpack/lib/action_controller/polymorphic_routes.rb
+++ b/actionpack/lib/action_controller/polymorphic_routes.rb
@@ -73,7 +73,7 @@ module ActionController
end
record = extract_record(record_or_hash_or_array)
- format = (options[:action].to_s == "formatted" and record_or_hash_or_array.pop)
+ format = extract_format(record_or_hash_or_array, options)
namespace = extract_namespace(record_or_hash_or_array)
args = case record_or_hash_or_array
@@ -152,6 +152,16 @@ module ActionController
end
end
+ def extract_format(record_or_hash_or_array, options)
+ if options[:action].to_s == "formatted" && record_or_hash_or_array.is_a?(Array)
+ record_or_hash_or_array.pop
+ elsif options[:format]
+ options[:format]
+ else
+ nil
+ end
+ end
+
def extract_namespace(record_or_hash_or_array)
returning "" do |namespace|
if record_or_hash_or_array.is_a?(Array)
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb
index 2cc01f61dc..df7d6ead1b 100644
--- a/actionpack/lib/action_controller/resources.rb
+++ b/actionpack/lib/action_controller/resources.rb
@@ -80,7 +80,9 @@ module ActionController
end
def new_path
- @new_path ||= "#{path}/new"
+ new_action = self.options[:path_names][:new] if self.options[:path_names]
+ new_action ||= Base.resources_path_names[:new]
+ @new_path ||= "#{path}/#{new_action}"
end
def member_path
@@ -266,6 +268,13 @@ module ActionController
# notes.resources :attachments
# end
#
+ # * <tt>:path_names</tt> - specify different names for the 'new' and 'edit' actions. For example:
+ # # new_products_path == '/productos/nuevo'
+ # map.resources :products, :as => 'productos', :path_names => { :new => 'nuevo', :edit => 'editar' }
+ #
+ # You can also set default action names from an environment, like this:
+ # config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' }
+ #
# * <tt>:path_prefix</tt> - set a prefix to the routes with required route variables.
#
# Weblog comments usually belong to a post, so you might use resources like:
@@ -515,8 +524,14 @@ module ActionController
resource.member_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
- map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}", action_options)
- map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action}.:format",action_options)
+ action_path = action
+ if resource.options[:path_names]
+ action_path = resource.options[:path_names][action]
+ action_path ||= Base.resources_path_names[action]
+ end
+
+ map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options)
+ map.named_route("formatted_#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}.:format",action_options)
end
end