【发布时间】:2014-04-01 06:05:14
【问题描述】:
我正在尝试在 rails 中实现一个链接,该链接将使用 delete: 方法指向某个 url,并且在 url 中有一些参数,我正在尝试的是:
<%= link_to "Remove", [:remove_country, :admin, @species, my_param: country.id ], method: :delete %>
注意我试图传入的 my_param: country.id。这给了我结果:
undefined method `model_name' for Hash:Class
由于参数中的哈希。不幸的是,我需要在那里,因为我试图将一个额外的参数传递到 url(my_param 在这个例子中是 country.id)
据我所知,这是将参数传递到 rails 中的 link_to 的正确方法。我使用的正常 link_to(没有 my_param)如下,效果很好:
<%= link_to "Remove from this species", url_for([:remove_country, :admin, @species]), method: :delete %>
那么我如何将我的参数合并到这个 url 中?提前致谢。 (here is a source for why I think this should work)
【问题讨论】:
标签: ruby-on-rails ruby link-to