options_from_collection_for_select -nomethoderror或grighterror-如何添加正确的参数?
在Rails Console
我编写类似的内容时: city.human_attribute_name(“模型”)
它的工作正常,返回值,但是当我尝试在.haml
中使用它时有错误。
= select_tag("select_tag", options_from_collection_for_select(@searchesForSelectTag, "name", 'human_attribute_name("model")', params[:select_tag]), {:include_blank => ' '})
nomethoderror:未定义的方法`human_attribute_name(“ model”)'for#< class:0x00007fdb90dddd1198>你的意思? human_attribute_name
@searchesforselecttag
- 这是类名称的数组(例如用户,城市,汽车...)。
当我只尝试这样的尝试时:“ human_attribute_name”
我有参数: 错误的参数数(给定0,预期1..2)
如何将参数“模型”添加到方法humy_attribute_name_name
in options_from_collection_for_select
中?
In Rails console
when I write Something like:City.human_attribute_name("model")
it's work correctly, a return value, but when I try to use it in .haml
in Options_from_collection_for_select
I have error.
= select_tag("select_tag", options_from_collection_for_select(@searchesForSelectTag, "name", 'human_attribute_name("model")', params[:select_tag]), {:include_blank => ' '})
NoMethodError: undefined method `human_attribute_name("model")' for #<Class:0x00007fdb90dd1198> Did you mean? human_attribute_name
@searchesForSelectTag
- this is array of classes name (eg. User, City, Car...).
When I try like only that : "human_attribute_name"
I have ArgumentError:wrong number of arguments (given 0, expected 1..2)
How can I add argument "model" to method human_attribute_name
in Options_from_collection_for_select
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在类上传递一个方法调用,而不是字符串:
更新
我找到了另一个带有动态类的解决方案。您可以尝试对此进行一些尝试。
Instead of a string, you can pass a method call on a class:
Update
I found another solution with dynamic classes. You can try to experiment something with this.