diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-05-28 01:04:27 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-05-28 01:04:27 +0000 |
commit | 062845b4da06f7025d6190899cde25deb8eaac42 (patch) | |
tree | b28a43a23934e42c34ac82d8d616c0195b95387d /actionpack/lib/action_view | |
parent | 0b1d6fd9c87fd4a8459b0f560db626bf36a19618 (diff) | |
download | rails-062845b4da06f7025d6190899cde25deb8eaac42.tar.gz rails-062845b4da06f7025d6190899cde25deb8eaac42.tar.bz2 rails-062845b4da06f7025d6190899cde25deb8eaac42.zip |
Expanded :method option in FormHelper#form_tag to allow for verbs other than GET and POST by automatically creating a hidden form field named _method, which will simulate the other verbs over post [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4371 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index c7a5d1bb2d..0db1977051 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -14,12 +14,27 @@ module ActionView # # Options: # * <tt>:multipart</tt> - If set to true, the enctype is set to "multipart/form-data". - # * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post". + # * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post". + # If "put", "delete", or another verb is used, a hidden input with name _method + # is added to simulate the verb over post. def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc) - html_options = { "method" => "post" }.merge(options.stringify_keys) + html_options = options.stringify_keys html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart") html_options["action"] = url_for(url_for_options, *parameters_for_url) - tag :form, html_options, true + + method_tag = "" + + case method = html_options.delete("method") + when /^get$/i # must be case-insentive, but can't use downcase as might be nil + html_options["method"] = "get" + when /^post$/i, nil + html_options["method"] = "post" + else + html_options["method"] = "post" + method_tag = tag(:input, :type => "hidden", :name => "_method", :value => method) + end + + tag(:form, html_options, true) + method_tag end alias_method :start_form_tag, :form_tag |