【问题标题】:Adding class to button_to in Rails not working在 Rails 中向 button_to 添加类不起作用
【发布时间】:2016-01-12 16:11:34
【问题描述】:

我正在尝试在 Rails 中添加一个带有 button_to 的类,但我不断收到语法错误。这就是我所拥有的:

<%= button_to "Update this task", user_task_path(current_user, task), method: "patch", remote: true, {class: "update"} %>

我尝试过将各种东西放入和取出牙套,但我无法让它发挥作用。有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails button-to


    【解决方案1】:

    编辑

    尝试使用 form_class(它将为您分配类)

    <%= button_to "Update this task", user_task_path(current_user, task), method: "patch", remote: true, form_class: "update" %>
    

    如果做不到这一点,一个更冗长的解决方案......

    <%= button_to user_task_path(current_user, task), {method: "patch", remote: true}, {class: "update"} do %>
      Update this task
    <% end %>
    

    【讨论】:

    • 嗯,这给了我“错误数量的参数(4 代表 0..3)”。
    猜你喜欢
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 2013-07-30
    • 2014-07-14
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多