"button" %> to a block in Rails 3?-6ren"> "button" %> to a block in Rails 3?-我想生成此链接: Search 据我了解,我必须转换 "button" %> 到一个 block ,但是当我这样做时: "button" do %> Search 它给了我以下错误: un-6ren">
gpt4 book ai didi

ruby-on-rails - 如何将 <%= link_to 转换为 "Upgrade"、 :settings, :class => "button" %> to a block in Rails 3?

转载 作者:行者123 更新时间:2023-12-03 00:46:46 24 4
gpt4 key购买 nike

我想生成此链接:

<a href="/settings" class="button"><span class="magnifier icon"></span>Search</a>

据我了解,我必须转换

<%= link_to "Upgrade", :settings, :class => "button" %>

到一个 block ,但是当我这样做时:

<%= link_to "Upgrade", :settings, :class => "button" do %>
<span class="magnifier icon">Search</span>
<% end %>

它给了我以下错误:

undefined method `stringify_keys' for :settings:Symbol

但是,当我这样做时:<%= link_to "Upgrade", :settings, :class => "button" %>它工作完美。

如何将其转换为 block ?

最佳答案

使用 block 时,第一个参数不再包含链接内容。该 block 对此负责。因此,它认为 "Upgrade" 是您链接的目标,而 :settings 是您的选项哈希。

删除“升级”并将其放入区 block 中。

关于ruby-on-rails - 如何将 <%= link_to 转换为 "Upgrade"、 :settings, :class => "button" %> to a block in Rails 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5307032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com