From 98fb161dbb13feb18165468aedf1581d5c2305f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 21 Aug 2008 18:26:05 +0100 Subject: Allow polymorphic_url helper to take url options. [#880 state:resolved] All *_polymorphic_url, *_polymorphic_path helpers can now accept an options hash which will be passed on to the named route making it possible to generate polymorphic routes with additional url parameters. Signed-off-by: Pratik Naik --- actionpack/lib/action_controller/polymorphic_routes.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index 7c30bf0778..30564c7bb3 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -102,6 +102,12 @@ module ActionController args << format if format named_route = build_named_route_call(record_or_hash_or_array, namespace, inflection, options) + + url_options = options.except(:action, :routing_type, :format) + unless url_options.empty? + args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options + end + send!(named_route, *args) end @@ -114,19 +120,19 @@ module ActionController %w(edit new formatted).each do |action| module_eval <<-EOT, __FILE__, __LINE__ - def #{action}_polymorphic_url(record_or_hash) - polymorphic_url(record_or_hash, :action => "#{action}") + def #{action}_polymorphic_url(record_or_hash, options = {}) + polymorphic_url(record_or_hash, options.merge(:action => "#{action}")) end - def #{action}_polymorphic_path(record_or_hash) - polymorphic_url(record_or_hash, :action => "#{action}", :routing_type => :path) + def #{action}_polymorphic_path(record_or_hash, options = {}) + polymorphic_url(record_or_hash, options.merge(:action => "#{action}", :routing_type => :path)) end EOT end private def action_prefix(options) - options[:action] ? "#{options[:action]}_" : "" + options[:action] ? "#{options[:action]}_" : options[:format] ? "formatted_" : "" end def routing_type(options) -- cgit v1.2.3