Reputation: 13308
In my Rails 3.2.3 application I'm using Ajax and jQuery. There is a link on a page and I want to replace it with a button. The code below is working perfect
<%= link_to "More", {:controller => "home", :action => "test_method", :page=>@current_page }, :remote => true,:id => 'lnk_more' %>
But this one doesn't
<%= button_to "More", {:controller => "home", :action => "test_method", :page=>@current_page }, :remote => true,:id => 'lnk_more' %>
The result html for a link and for a button is here
#link
<a href="/home/test_method?page=1" data-remote="true" id="lnk_more" disabled="disabled">More </a>
#button
<form action="/home/test_method?page=1" class="button_to" data-remote="true" method="post"><div><input id="lnk_more" type="submit" value="More "><input name="authenticity_token" type="hidden" value="hFCuBR+88FYKEvNTZok+QRhxf6fHA+ucC6i2yc9hBEk="></div></form>
What have I done wrong?
Upvotes: 2
Views: 4630
Reputation: 4930
You must change the method :method=>:get
, since by default it is set to post
. And your routes are probably not routing it correctly
<%= button_to "More", {:controller => "home", :action => "test_method", :page=>@current_page }, :method=>:get, :remote => true,:id => 'lnk_more' %>
Upvotes: 1
Reputation: 14943
<%= button_to "More",
{ :controller => :home, :action=> :test_method, :page => @current_page},
{ :remote => true, :id => 'lnk_more' }
%>
will give an id to the input
<input id="lnk_more" type="submit" value="More">
Upvotes: 3
Reputation: 4515
According to the documentation the remote
option should be part of options
. See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to
Upvotes: 0