2

在我的 Rails 3.2.3 应用程序中,我使用 Ajax 和 jQuery。页面上有一个链接,我想用一个按钮替换它。下面的代码运行完美

<%= link_to "More", {:controller => "home", :action => "test_method", :page=>@current_page }, :remote => true,:id => 'lnk_more' %>

但是这个不

<%= button_to "More", {:controller => "home", :action => "test_method", :page=>@current_page }, :remote => true,:id => 'lnk_more' %>

链接和按钮的结果 html 在这里

#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>

我做错了什么?

4

3 回答 3

3
<%= button_to "More", 
     { :controller => :home, :action=> :test_method, :page => @current_page}, 
     { :remote => true, :id => 'lnk_more' } 
 %>

会给输入一个id

<input id="lnk_more" type="submit" value="More">
于 2012-07-16T16:46:41.497 回答
1

您必须更改方法:method=>:get,因为默认情况下它设置为post. 而且您的路线可能没有正确路由

<%= button_to "More", {:controller => "home", :action => "test_method", :page=>@current_page }, :method=>:get, :remote => true,:id => 'lnk_more' %>

于 2012-08-11T06:05:17.650 回答
0

根据文档,该remote选项应该是options. 请参阅http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to

于 2012-07-16T16:43:18.883 回答