mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow FormHelper#form_for to specify the :method as a direct option instead of through the :html hash [DHH]
This commit is contained in:
parent
dea3d2dd20
commit
f8a05ad297
3 changed files with 37 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
|||
*Rails 3.1.0 (unreleased)*
|
||||
|
||||
* Allow FormHelper#form_for to specify the :method as a direct option instead of through the :html hash [DHH]
|
||||
|
||||
form_for(@post, remote: true, method: :delete) instead of form_for(@post, remote: true, html: { method: :delete })
|
||||
|
||||
* Make JavaScriptHelper#j() an alias for JavaScriptHelper#escape_javascript() -- note this then supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper [DHH]
|
||||
|
||||
* Sensitive query string parameters (specified in config.filter_parameters) will now be filtered out from the request paths in the log file. [Prem Sichanugrist, fxn]
|
||||
|
|
|
@ -185,7 +185,7 @@ module ActionView
|
|||
#
|
||||
# is equivalent to something like:
|
||||
#
|
||||
# <%= form_for @post, :as => :post, :url => post_path(@post), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %>
|
||||
# <%= form_for @post, :as => :post, :url => post_path(@post), :method => :put, :html => { :class => "edit_post", :id => "edit_post_45" } do |f| %>
|
||||
# ...
|
||||
# <% end %>
|
||||
#
|
||||
|
@ -236,6 +236,16 @@ module ActionView
|
|||
# Where <tt>@document = Document.find(params[:id])</tt> and
|
||||
# <tt>@comment = Comment.new</tt>.
|
||||
#
|
||||
# === Setting the method
|
||||
#
|
||||
# You can force the form to use the full array of HTTP verbs by setting
|
||||
#
|
||||
# :method => (:get|:post|:put|:delete)
|
||||
#
|
||||
# in the options hash. If the verb is not GET or POST, which are natively supported by HTML forms, the
|
||||
# form will be set to POST and a hidden input called _method will carry the intended verb for the server
|
||||
# to interpret.
|
||||
#
|
||||
# === Unobtrusive JavaScript
|
||||
#
|
||||
# Specifying:
|
||||
|
@ -298,7 +308,7 @@ module ActionView
|
|||
#
|
||||
# In this case, if you use this:
|
||||
#
|
||||
# <%= render :partial => f %>
|
||||
# <%= render f %>
|
||||
#
|
||||
# The rendered template is <tt>people/_labelling_form</tt> and the local
|
||||
# variable referencing the form builder is called
|
||||
|
@ -350,6 +360,7 @@ module ActionView
|
|||
end
|
||||
|
||||
options[:html][:remote] = options.delete(:remote)
|
||||
options[:html][:method] = options.delete(:method) if options.has_key?(:method)
|
||||
options[:html][:authenticity_token] = options.delete(:authenticity_token)
|
||||
|
||||
builder = options[:parent_builder] = instantiate_builder(object_name, object, options, &proc)
|
||||
|
|
|
@ -715,14 +715,31 @@ class FormHelperTest < ActionView::TestCase
|
|||
assert_dom_equal expected, output_buffer
|
||||
end
|
||||
|
||||
def test_form_for_with_method
|
||||
form_for(@post, :url => '/', :html => { :id => 'create-post', :method => :put }) do |f|
|
||||
def test_form_for_with_method_as_part_of_html_options
|
||||
form_for(@post, :url => '/', :html => { :id => 'create-post', :method => :delete }) do |f|
|
||||
concat f.text_field(:title)
|
||||
concat f.text_area(:body)
|
||||
concat f.check_box(:secret)
|
||||
end
|
||||
|
||||
expected = whole_form("/", "create-post", "edit_post", "put") do
|
||||
expected = whole_form("/", "create-post", "edit_post", "delete") do
|
||||
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
||||
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
||||
"<input name='post[secret]' type='hidden' value='0' />" +
|
||||
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
|
||||
end
|
||||
|
||||
assert_dom_equal expected, output_buffer
|
||||
end
|
||||
|
||||
def test_form_for_with_method
|
||||
form_for(@post, :url => '/', :method => :delete, :html => { :id => 'create-post' }) do |f|
|
||||
concat f.text_field(:title)
|
||||
concat f.text_area(:body)
|
||||
concat f.check_box(:secret)
|
||||
end
|
||||
|
||||
expected = whole_form("/", "create-post", "edit_post", "delete") do
|
||||
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
||||
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
||||
"<input name='post[secret]' type='hidden' value='0' />" +
|
||||
|
|
Loading…
Reference in a new issue