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

1

5

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.

Calvary answered 24/12, 2010 at 19:58 Comment(0)
C
7

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
Calvary answered 24/12, 2010 at 20:44 Comment(2)
Thanks, I've been banging my head for the last 4 hours!Cornellcornelle
Me as well, several hours of head banging.Hokkaido

© 2022 - 2024 — McMap. All rights reserved.