Rails: Can't set or update tag_list using a text field with acts_as_taggable_on
Hey everyone, I'm trying to add tagging to a 开发者_开发技巧rails photo gallery system I'm working on. It works from the back-end, but if I try to set or change it in the form view, it doesn't work.
I added acts_as_taggable to the photo model and did the migrations. My gallery builder is programmed to add one tag automatically to each photo it creates. This works fine, just as if it were setting it for the console. However, I can't seem to set tags using a text_field in the photo form.
Here's the code I added to my photo form:
<p>
<%= f.label :tag_list %><br />
<%= f.text_field :tag_list %>
</p>
Now, that's pretty trivial, and since :tag_list supports single-string comma-separated assignment (e.g. tag_list = "this, that, the other" #=> ['this', 'that', 'the other']), I don't see why using a text field doesn't work. And to make even less sense, if a tag list has already been populated, the list will still show up in the text field when editing the photo. I just can't seem to commit any changes to the list. The documentation on their github page doesn't appear to give any information on how to set these values from the view. Any ideas?
Oh, and I'm using the Rails 3 gem version.
I figured it out. Turns out that acts_as_taggable doesn't give you accessors for tag_list automatically. My code in the view was right, but I needed to add
attr_accessor :tag_list
do the photo model. Simple as that.
精彩评论