Acts_as_taggable help


#1

Ahoy, having a bit of difficulty w/ the acts as taggable GEM.
I was able to create a tagcloud, but now i want to filter items by tags.

in my controller i have

def show_tagged_with
<-- snip snip -->
@items = Item.find_tagged_with( :any => params[:tag_name])
@categories = Category.find_all
@tag_name = params[:tag_name]
@tagged_items = Item.tags_count(:limit => 100)
end

IN the VIEW
<% @items.each do |item| %>
<%= render :partial => ‘list_stripes’, :locals => { :item => item } %>
<% end %>

Where the partial _list_stripes.rthml is a list of items

<td><%=h item.tag_names.join(" ") %></td>
<td><%=h item.created_on %></td>
<td><%=h item.category.name %></td>

But i get an error

“undefined method `tag_names’ for #Array:0x3673b08

any ideas?


#2

Example of what works. Convert for your needs.

in tags_controller.rb

def info
@name = params[:name]
@tag = Tag.find(:first, :conditions => “name = ‘#{@name}’”)
end

in info.rhtml
<% for @item in @tag.tagged %>
<%= render :partial => “render_item” %>
<% end %>

in the partial _render_item.rhtml

<%= @ item.name -%>

<%= @ item.description -%>

On 4/28/06, will removed_email_address@domain.invalid wrote:

@tag_name   = params[:tag_name]


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails