Ruby-on-rails Rails - 未定义的方法“stringify_keys”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14986559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails - Undefined method `stringify_keys'
提问by scientiffic
I'm trying to create a block of ruby code for when a user clicks on the back button. I'm getting the error "undefined method `stringify_keys' for "/projects/11/steps/4":String". The code works when I get rid of the do and end. How do I add a do to a link_to?
我正在尝试为用户单击后退按钮时创建一个 ruby 代码块。我收到“/projects/11/steps/4”的错误“未定义方法`stringify_keys':String”。当我摆脱 do 和 end 时,代码有效。如何向 link_to 添加 do?
<%= link_to 'Back', project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>
<% end %>
回答by nzifnab
If you're using the block form of link_toyou can't have text content (the block is your text content). You'd need to do this:
如果您使用的是块形式,link_to则不能有文本内容(块是您的文本内容)。你需要这样做:
<%= 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 :)
通常,当您希望将图像或其他标签作为链接内容时使用。它纯粹是为了展示目的。该块不会为您提供类似 javascript 的功能,因此请确保您在此处寻找其他显示行为:)
回答by Marlin Pierce
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 %>

