Forum: Ruby on Rails acts_as_taggable Plugin issue (not gem)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
boboroshi (Guest)
on 2006-12-31 01:38
(Received via mailing list)
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*
<code>
<h1>Listing elements</h1>

<% if @elements.blank? %>
	<p>There are currently no elements in the system tagged <%=
"&quot;#{params[:tag_name]}&quot;" %>.</p>
<% else %>
	<p>Currently tracking <%= @elements.size %> elements in the system
tagged <%= "&quot;#{params[:tag_name]}&quot;" %>.</p>


<table>
  <tr>
  </tr>

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

</table>

<% end %>
<br />

<%= link_to 'New element', new_element_path %>
</code>

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*

<code>
  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
</code>

*Models*

<code>
class Element < ActiveRecord::Base

  acts_as_taggable
  [...]
end
</code>


*CONSOLE*

This does work:
<code>
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
</code>
This topic is locked and can not be replied to.