Ruby on rails 链接到语法,多个选项

Ruby on rails 链接到语法,多个选项,ruby-on-rails,Ruby On Rails,我无法按我想要的方式获取链接。目前,我有以下代码: <%= link_to :action => 'toggle' , :id => item.id, :remote => true do %> <i class="icon icon-test"></i><b>Toggle</b> <%end%> 给我一些错误,比如 语法错误,意外的tASSOC,应为“}” 我想我想调用列出的第三个签名,但

我无法按我想要的方式获取链接。目前,我有以下代码:

<%= link_to  :action => 'toggle' ,  :id => item.id, :remote => true  do %>
    <i class="icon icon-test"></i><b>Toggle</b>
<%end%>
给我一些错误,比如

语法错误,意外的tASSOC,应为“}”


我想我想调用列出的第三个签名,但语法似乎不正确。

您应该使用URL帮助程序,而不是对URL使用哈希参数:

<%= link_to toggle_item_path(item), :remote => true do %>
  <i class="icon icon-test"></i><b>Toggle</b>
<% end %>
true do%>
切换
这不仅更短,而且Rails也不会混淆什么键属于什么散列


中阅读更多关于
切换项目路径的信息,这将为我提供
NoMethodError
。如果我先执行其他操作,是否会生成此方法?您需要为此定义一个成员路由,这在我链接到的路由指南中有介绍。
<%= link_to toggle_item_path(item), :remote => true do %>
  <i class="icon icon-test"></i><b>Toggle</b>
<% end %>