aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-05 19:10:59 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-05 19:10:59 +0000
commit5dd3db86157ce2bd08c4ec07826d3aaf5c29f458 (patch)
treedfaa4c5731772c1d5a9f59d76fa3a76cbb4b51df /actionpack/lib/action_view/helpers/form_helper.rb
parentb83efadb32fe55ba7a7d23d650a8adc1a351eab7 (diff)
downloadrails-5dd3db86157ce2bd08c4ec07826d3aaf5c29f458.tar.gz
rails-5dd3db86157ce2bd08c4ec07826d3aaf5c29f458.tar.bz2
rails-5dd3db86157ce2bd08c4ec07826d3aaf5c29f458.zip
Resources: url_for([parent, child]) generates /parents/1/children/2 for the nested resource. Likewise with the other simply helpful methods like form_for and link_to. Closes #6432.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6951 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb29
1 files changed, 17 insertions, 12 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 7325aad398..1a4aa0ca05 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -163,9 +163,14 @@ module ActionView
case record_or_name
when String, Symbol
object_name = record_or_name
+ when Array
+ object = record_or_name.last
+ object_name = ActionController::RecordIdentifier.singular_class_name(object)
+ apply_form_for_options!(object, options, *record_or_name)
+ args.unshift object
else
- object = record_or_name
- object_name = ActionController::RecordIdentifier.singular_class_name(record_or_name)
+ object = record_or_name
+ object_name = ActionController::RecordIdentifier.singular_class_name(object)
apply_form_for_options!(object, options)
args.unshift object
end
@@ -174,18 +179,18 @@ module ActionView
fields_for(object_name, *(args << options), &proc)
concat('</form>', proc.binding)
end
-
- def apply_form_for_options!(object, options) #:nodoc:
- html_options = if object.respond_to?(:new_record?) && object.new_record?
- { :class => dom_class(object, :new), :id => dom_id(object), :method => :post }
- else
- { :class => dom_class(object, :edit), :id => dom_id(object, :edit), :method => :put }
- end
-
+
+ def apply_form_for_options!(object, options, *nested_objects) #:nodoc:
+ html_options =
+ if object.respond_to?(:new_record?) && object.new_record?
+ { :class => dom_class(object, :new), :id => dom_id(object), :method => :post }
+ else
+ { :class => dom_class(object, :edit), :id => dom_id(object, :edit), :method => :put }
+ end
+
options[:html] ||= {}
options[:html].reverse_merge!(html_options)
-
- options[:url] ||= polymorphic_path(object)
+ options[:url] ||= polymorphic_path(object, *nested_objects)
end
# Creates a scope around a specific model object like form_for, but doesn't create the form tags themselves. This makes