Rails3 actions_as_taggable 带有表单
我刚刚开始使用acts_as_taggable gem。到目前为止我真的很喜欢它,但我有点不清楚如何将这个 gem 与表单一起使用。
class Photo < ActiveRecord::Base
acts_as_taggable_on :tags
end
在我的照片表单中,我试图实现一系列复选框,以便用户为他们的照片分配标签:
<%= f.label :tag_list %>
<%= f.check_box :tag_list, "landscape" %>
<%= f.check_box :tag_list, "people" %>
查看表单时,我收到此错误:
NoMethodError in Photos#edit
...line #19 raised:
undefined method `merge' for "landscape":String
Extracted source (around line #19):
18: <div class="float_tag">
19: <%= f.check_box :tag_list, "landscape" %>
关于如何创建表单有什么想法吗?
I've just started working with the acts_as_taggable gem. Really liking it so far, but I am a bit unclear about how to use this gem with a form.
class Photo < ActiveRecord::Base
acts_as_taggable_on :tags
end
In my form for Photos I am trying to implement a series of checkboxes for the user to assign tags to their photo:
<%= f.label :tag_list %>
<%= f.check_box :tag_list, "landscape" %>
<%= f.check_box :tag_list, "people" %>
When viewing the form I get this error:
NoMethodError in Photos#edit
...line #19 raised:
undefined method `merge' for "landscape":String
Extracted source (around line #19):
18: <div class="float_tag">
19: <%= f.check_box :tag_list, "landscape" %>
Any thoughts as to how I should create my form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您的
您应该稍微更改一下
f.checkbox
行:提交时会发布类似的内容(使用仅选择人员,例如):
I'm assuming your
<form>
looks something like this:You should change up your
f.checkbox
lines a bit:Which will post something like this when submitted (with only people selected, for example):
对于任何试图让它与 Rails 4 和强参数一起工作的人,我还必须允许 tag_list 参数作为数组。
For anyone trying to get this to work with Rails 4 and strong parameters, I also had to permit the the tag_list param as an array.