Acts_as_taggable Plugin issue (not gem)


#1

I tried to post this earlier, but it never came through. I’ve got
something working in console, but not in controller. Any idea why?

This is the plugin not the gem of acts_as_taggable

View

Listing elements

<% if @elements.blank? %>

There are currently no elements in the system tagged <%=
“”#{params[:tag_name]}"" %>.


<% else %>

Currently tracking <%= @elements.size %> elements in the system
tagged <%= “”#{params[:tag_name]}"" %>.

	<%= render :partial => 'element', :collection => @elements %>

<% end %>

<%= link_to ‘New element’, new_element_path %>

This returns that the array is empty and there’s nothing in the tag in
http://localhost:3000/elements/tagged/:tag_name

SO teh view is seeing it, but the controller is not getting it. Because
in the console, using a string in place of params(:tag_name) returns an
actual entry.

Controller

def tagged # This should take the :tag_name in the url string and pull elements that match # It does not. I suck as a programmer. @elements = Element.find_tagged_with(params[:tag_name])
respond_to do |format|
  format.html # index.rhtml
  format.xml  { render :xml => @elements.to_xml }
end

end

Models

class Element < ActiveRecord::Base

acts_as_taggable
[…]
end

CONSOLE

This does work:

soho:~/Sites/work/koji jathayde$ script/console
Loading development environment.

@elements = Element.find_tagged_with(“spam”)
DEPRECATION WARNING: The :dependent => true option is deprecated and
will be removed from Rails 2.0. Please use :dependent => :destroy
instead. See http://www.rubyonrails.org/deprecation for details. See
http://www.rubyonrails.org/deprecation for details. (called from
has_many at
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/associations.rb:550)
=> [#<Element:0x330a8d8 @attributes={“name”=>“Koji Test One”,
“updated_at”=>“2006-11-30 18:16:40”, “id”=>“1”, “description”=>“supa
sexy description”, “filename”=>nil, “element_type_id”=>“3”,
“created_at”=>nil}]

But this does not (because there is no value in params[:tag_list]:

@elements = Element.find_tagged_with(params[:tag_list])
NameError: undefined local variable or method `params’ for
#Object:0x1f59f0
from (irb):4
from :0