【问题标题】:Turn a button to a link with the same exact functionality将按钮转到具有相同功能的链接
【发布时间】:2011-07-19 00:57:47
【问题描述】:

所以我有这个按钮:

<%= button_to "+1", video_votes_path( :video_id => video.id, :type => "up" ), :remote => true %>

它调用 video_votes 控制器中的 create 方法,并设置 params[:type]。我想把这个按钮变成一个链接,这样它就完成了完全相同的事情。我该怎么做?

【问题讨论】:

  • 难道你想作为链接的按钮的 css 类不能解决问题,而不是 ajax 远程?这就是我所做的:在用户 pov 中,它是一个链接,但他点击了一个按钮,提交了表单。

标签: ruby-on-rails ruby ruby-on-rails-3 button hyperlink


【解决方案1】:
button_to "+1", video_votes_path( :video_id => video.id, :type => "up" ), :remote => true
=>
link_to "+1", video_votes_path( video, :type => "up"), :remote => true, :method => :post

【讨论】:

    【解决方案2】:

    button_to改成link_to_remote,加上一个额外的参数::method =&gt; :post,去掉remote

    呃,如果您想要 GET,请忽略 method

    【讨论】:

    • 为什么要取出遥控器?不应该是link_to 并通过remote =&gt; true 作为选项吗?
    • link_to_remote 已弃用,取而代之的是 link_toremote =&gt; true
    猜你喜欢
    • 2018-03-03
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    • 2017-07-07
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多