"test_meth-6ren">
gpt4 book ai didi

ruby-on-rails - Rails - link_to 和 button_to

转载 作者:行者123 更新时间:2023-12-04 18:16:45 26 4
gpt4 key购买 nike

在我的 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>

我做错了什么?

最佳答案

<%= 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">

关于ruby-on-rails - Rails - link_to 和 button_to,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11508673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com