diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2006-02-11 23:29:53 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2006-02-11 23:29:53 +0000 |
commit | 344ae8326a51beabbc5b3f4f851c3d65ec789e2d (patch) | |
tree | 9e017c6dac888f0ad5d76d7b16bf34691816cdd7 /actionpack/lib | |
parent | 91cdd59b12d4101c3dc1130cf0f2b4543a14eb79 (diff) | |
download | rails-344ae8326a51beabbc5b3f4f851c3d65ec789e2d.tar.gz rails-344ae8326a51beabbc5b3f4f851c3d65ec789e2d.tar.bz2 rails-344ae8326a51beabbc5b3f4f851c3d65ec789e2d.zip |
Remove over-engineered form_for code for a leaner implementation.
Document form_for's :html option.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3572 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 39 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 4 |
2 files changed, 16 insertions, 27 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 872453b753..81f6fec827 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -98,6 +98,12 @@ module ActionView # Note: This also works for the methods in FormOptionHelper and DateHelper that are designed to work with an object as base. # Like collection_select and datetime_select. # + # Html attributes for the form tag can be given as :html => {...}. Example: + # + # <% form_for :person, @person, :html => {:id => 'person_form'} do |f| %> + # ... + # <% end %> + # # You can also build forms using a customized FormBuilder class. Subclass FormBuilder and override or define some more helpers, # then use your custom builder like so: # @@ -115,22 +121,9 @@ module ActionView # end # def form_for(object_name, object, options = {}, &proc) - raise ArgumentError, "form_for requires a block!" unless proc - - url_options = options.delete(:url) || {} - form_tag_selector = options.delete(:form_tag_selector) || :form_tag - form_options = options.delete(:html) || {} - [:method, :multipart].each { |key| form_options[key] = options.delete(key) if options.key? key } - - fields_for(object_name, object, options.merge(:proc => proc)) do |builder| - if form_tag_selector == :form_remote_tag - concat send(form_tag_selector, form_options.merge(:url => url_options, :html => form_options)), proc.binding - else - concat send(form_tag_selector, url_options, form_options), proc.binding - end - builder.build_form(url_options, form_options) { proc.call builder } - concat end_form_tag, proc.binding - end + concat form_tag(options, options.delete(:html) || {}), proc.binding + fields_for(object_name, object, options, &proc) + concat '</form>', proc.binding end # Creates a scope around a specific model object like form_for, but doesn't create the form tags themselves. This makes @@ -148,11 +141,10 @@ module ActionView # Note: This also works for the methods in FormOptionHelper and DateHelper that are designed to work with an object as base. # Like collection_select and datetime_select. def fields_for(object_name, object, options = {}, &proc) - raise ArgumentError, "fields_for requires a block!" unless proc - - builder = options[:builder] || FormBuilder - form_builder = builder.new(object_name, object, self, options, options[:proc] || proc) - proc.call(form_builder) + raise ArgumentError, "fields_for requires a block!" unless block_given? + builder_klass = options[:builder] || FormBuilder + form_builder = builder_klass.new(object_name, object, self, options, proc) + yield form_builder end # Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by +method+) on an object @@ -389,11 +381,6 @@ module ActionView @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc end - # An empty stub that can be overriden to wrap a form created by form_for. - def build_form(url_options, form_options, &proc) - proc.call self - end - (field_helpers - %w(check_box radio_button)).each do |selector| src = <<-end_src def #{selector}(method, options = {}) diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 523adb3288..96f065cc11 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -172,7 +172,9 @@ module ActionView # Works like form_remote_tag, but uses form_for semantics. def remote_form_for(object_name, object, options = {}, &proc) - form_for(object_name, object, options.merge(:form_tag_selector => :form_remote_tag), &proc) + concat form_remote_tag(options), proc.binding + fields_for(object_name, object, options, &proc) + concat '</form>', proc.binding end alias_method :form_remote_for, :remote_form_for |