|
Articles tagged be_taggable
Be_Taggable, the commercial ;)
=== acting troupe
actor1 (be): be_taggable, need to be hot and attractive.
actor2 (acts): acts_as_taggable, need to be anyone but hot and attractive.
=== scene 1
acts: Hi, my name is acts_as_taggable.
be: Hi, my name is be_taggable.
acts: hmmm... never heard of.
be: That's ok, I can do what you do, but much easier and efficient.
acts: oh yeah? how so?
be: my name has only 11 letters, 5 less than yours, a 31.25% improvement.
*Acts laugh hysterically*
acts: wow, I'm really impressed.
be: *unfazed, continues calmly*
I have just 67 lines of code, 1/10th of your size.
*Acts looking suspiciously at Be for a few seconds*
acts: can you tag any models?
be: yes, without creating additional join tables.
acts: can you find by tags?
be: you mean Tag.find_by_name ? yes, you can find by tags, by model class,
by count, or any combination of it.
*Acts's face gets red*
be: plus for model tables, I added tags_cache column to reduce DB traffic.
be: Run 3 shell commands will get you started right away, no need to create
tables by hand.
*Acts faint and fall back onto the ground*
be: Did I say too much?
*Camera zoom out, blurs*
*Display URL http://railers.rubyforge.org/be_taggable *
Many thanks to acts_as_taggable. be_taggable becomes small by standing on the shoulder of acts_as_taggable giant.
Views: 1213
Replies: 1
Last Reply:
eilson,
09/28/2007.
Tags:
be_taggable
Meet be_taggable pluginOriginally I planned to use the Acts_as_taggable gem, then i check out the code, and just can't accept how can simple tagging takes 675 lines. So by "borrowing" code from that gem, I've created be_taggable plugin, major improvements:
Installsvn export http://railers.rubyforge.org/svn/plugins/trunk/be_taggable
script/generate be_taggable_tables Article Bookmark ... # models to be tagged
rake db:migrate
Usage Class TestBook
be_taggable # Mark your class be_taggable.
...
end
book = TestBook.create(:name => "AWDWR")
book.tag("programming, rails") # 2 tags added
book.tag("agile, rails") # "programming" removed,
"agile" added,
"rails" untouched.
hash = TestBook.tags_count # {"rails" => 1, "agile" => 1}
book.tag("") # remove all tags.
TestBook.find_tagged_with("rails") # return list of matching book objects.
TestBook.find_tagged_with("rails", :offset => 20, :limit => 10) # search with options.
and in template
# To display model‘s tags from tags_cache column.
<% for tag in YAML::load(article.tags_cache) %>
<%= link_to(tag, tagged_articles_path(tag)) # assume route exists %>
<% end -%>
# To show tag cloud
<table>
<% Article.tags_count.sort.each{|pair| %>
<tr>
<td><%= link_to(pair[0], tagged_articles_path(pair[0])) %></td>
<td><%= pair[1] # count %></td>
</tr>
<% } %>
</table>
ReferenceDocumentation: http://railers.rubyforge.org/be_taggable/Code: svn export http://railers.rubyforge.org/svn/plugins/trunk/be_taggable
Views: 1188
Replies: 0
Tags:
be_taggable,
plugin
|
login or sign up
to participate.
Tags
moneywill |
|||||||||||||||||||||||||||||||