Rails3 act_as_taggable 带有一个表单 [英] Rails3 acts_as_taggable with a form
问题描述
我刚刚开始使用acts_as_taggable gem.到目前为止真的很喜欢它,但我有点不清楚如何将这个 gem 与表单一起使用.
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?
推荐答案
我假设你的 看起来像这样:
I'm assuming your <form>
looks something like this:
<%= form_for(@photo) do |f| %>
<%= f.label :tag_list %>
<%= f.check_box :tag_list, "landscape" %>
<%= f.check_box :tag_list, "people" %>
<% end %>
你应该稍微改变一下你的 f.checkbox
行:
You should change up your f.checkbox
lines a bit:
<%= form_for(@photo) do |f| %>
<%= f.label :tag_list %>
<%= f.check_box :tag_list, { :multiple => true }, 'landscape', nil %>
<%= f.check_box :tag_list, { :multiple => true }, 'people', nil %>
<% end %>
提交时会发布类似的内容(例如,仅选择人员):
Which will post something like this when submitted (with only people selected, for example):
{ :post => { :tag_list => ['', 'people'] } }
这篇关于Rails3 act_as_taggable 带有一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!