Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acts-as-taggable-on - Trouble putting all of the pieces together

I'm having a heck of a time getting acts-as-taggable-on working. I am new to Ruby/RoR, and I feel that sometimes these plugins (although great) lack the very basic implementation instructions for people who aren't used to working in Rails.

I have a simple Content model that I want to be able to add tags to. When I save the form, nothing happens. I try to output the tags and nothing is showing (I've gone into rails console, nothing). Do I need an additional attribute (column) on my Content model (table)? I have a feeling I'm missing something very basic.

Content model:

class Content < ActiveRecord::Base
    acts_as_taggable
    # I've also tried acts_as_taggable :tags
end

In my form partial:

<p>
  <%= f.label 'Tags' %><br />
  <%= f.text_field :tag_list %>
</p>

In my show.html.erb:

<p>
    <strong>Tags</strong>: 
    <% for tag in @content.tags %> 
        <%= link_to tag.name, contents_path(:view =>'tag', :tag => tag.name) %>
    <% end %>
</p>

I'm hoping someone can get me pointed in the right direction. Thanks!


edit

Here's a link to the logs, you can see it's saving the tag_list.

like image 729
jyoseph Avatar asked Dec 24 '10 19:12

jyoseph


1 Answers

Found the problem. After posting a link to the logs I noticed this:

WARNING: Can't mass-assign protected attributes: tag_list

I needed to add :tag_list to attr_accessible:

attr_accessible :name, :desc, :tag_list
like image 106
jyoseph Avatar answered Sep 18 '22 20:09

jyoseph