Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make button_to helper support data-type option. This attribute should…

… put into form tag with data-remote, not input tag.
  • Loading branch information...
commit 09dc54a83a2e7a05b1345371c57cc5524875bced 1 parent f3b8cd9
@ihower authored
View
5 actionpack/lib/action_view/helpers/url_helper.rb
@@ -327,7 +327,8 @@ def button_to(name, options = {}, html_options = {})
form_class = html_options.delete('form_class') || 'button_to'
remote = html_options.delete('remote')
-
+ data_type = html_options.delete('data-type')
+
request_token_tag = ''
if form_method == 'post' && protect_against_forgery?
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
@@ -340,7 +341,7 @@ def button_to(name, options = {}, html_options = {})
html_options.merge!("type" => "submit", "value" => name)
- ("<form method=\"#{form_method}\" action=\"#{ERB::Util.html_escape(url)}\" #{"data-remote=\"true\"" if remote} class=\"#{ERB::Util.html_escape(form_class)}\"><div>" +
+ ("<form method=\"#{form_method}\" action=\"#{ERB::Util.html_escape(url)}\" #{"data-remote=\"true\"" if remote} #{"data-type=\"#{data_type}\"" if data_type} class=\"#{ERB::Util.html_escape(form_class)}\"><div>" +
method_tag + tag("input", html_options) + request_token_tag + "</div></form>").html_safe
end
View
7 actionpack/test/template/url_helper_test.rb
@@ -109,6 +109,13 @@ def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_wit
)
end
+ def test_button_to_with_remote_and_data_type
+ assert_dom_equal(
+ "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\" data-type=\"json\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
+ button_to("Hello", "http://www.example.com", :remote => true, "data-type" => "json")
+ )
+ end
+
def test_button_to_with_remote_false
assert_dom_equal(
"<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
Please sign in to comment.
Something went wrong with that request. Please try again.