With acts_as_taggable 1.04…
- how can I get a frequency of tags?
i.e. /tags/list I want to list of tags sorted and listed with
their frequency
tags_controller.rb:
def list
@tags = Tags.find_by_sql 'select name, count(*) as freq from tags
group by name order by freq desc’
End
tags/list.rb:
<ul>
<% @tags.each do |t| %>
<li><%= t.freq %> <%= t.name %></li>
<% end %>
</ul>
According to the acts_as_taggable gem rdocs
(ActiveRecord::Acts::Taggable::ClassMethods) I should be using
Issues.tags_count, but I get a NoMethodError. Any ideas? This
doesn’twork in the console either.
(I’ve since opened up taggable.rb and taken a look at the sql
involved. I have figured out the sql to do this in MS SQLserver to
give me the correct results, but this still doesn’t solve the
NoMethodError)
- I cannot add tags to my models via my UI but I can add them via the
script/console. When I try to add them via the UI in
issues_controller.rb I get a NoMethodError
issues_controller.rb
def create
@issues = Issues.new(params[:issues])
@issues.tag params[:tags] # NoMethodError raised here
if @issues.save
flash[:notice] = 'Issues was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
issues/_form.rhtml
<!--[form:issues]-->
<p><label for="issues_name">Name</label><br/>
<%= text_field 'issues', 'name' %></p>
<p><label for="issues_add_tags">Tags</label><br/>
<%= text_field 'tags', '' %></p>
<!--[eoform:issues]-->
My params[:tags] are getting populated correctly.
–
Craig B.
http://www.luckybonza.com
AIM: kreiggers