Rails-未定义的方法‘ stringify_keys’

我试图创建一个块的红宝石代码,当用户点击后退按钮。我得到了“/project/11/step/4“ : String”的未定义方法‘ stringify _ keys’错误。当我去掉 do 和 end 时,代码可以工作。如何向 link _ to 添加 do?

    <%= link_to 'Back', project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>


<% end %>
39208 次浏览

If you're using the block form of link_to you can't have text content (the block is your text content). You'd need to do this:

<%= link_to project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>
Back
<% end %>

Typically this is used when you want to have images or other tags as the contents of the link. It's purely for display purposes. The block will not give you javascript-like functionality, so make sure additional display behavior is what you're looking for here :)

If you pass a block then do not pass the link name. Should be:

<%= link_to project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>
Back
<% end %>