Articles tagged plugin

How to config plugin classes in dev/test/prod env file
Dorren_mii_thumb by dorren, 10/02/2007
Most of plugins set initial configuration values in default environment.rb file. What if you've written a plugin, and you want to set different config values in each environment, in RAILS_ROOT/config/environments/XXX.rb? You can't do that directly.

For example, If you have a Widget class in your plugin, and you want to set Widget.param=123 in test.rb, what you get is a big fat class not found error, like
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:266:in `load_missing_constant': uninitialized constant Widget (NameError)
The reason for that is when rails is starting up and processing each environment file, it hasn't load any plugins yet, so it doesn't know about your plugin classes. When I searched the web for solutions, people tried modifying rails initializer or other similar crazy stuff.

The solution is quite simple, just do it afterwards.

at the end of my environment.rb, just add require File.join(File.dirname(__FILE__), "environments/#{ENV['RAILS_ENV'] || 'test'}_post_init")
"|| 'test'" part is need for rake. then put your plugin configuration code in environments/test_post_init.rb, development_post_init.rb, and production_post_init.rb

If any of the config values are used in config/routes.rb, make sure to copy that line in the beginning of routes.rb file too.

Views: 1461   Replies: 0   Tags: plugin
Be_taggable plugin, 1/10th size of acts_as_taggable
Dorren_mii_thumb by dorren, 09/18/2007

Meet be_taggable plugin


Originally 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:
  • The name Be_taggable is 5 letters less, or 31.25% more efficient.
  • BeTaggable module weights 67 lines, compare to 675 lines, a whopping 90% improvement.
  • Built in tags_cache column to reduce DB traffic.
  • Simple installation, run 3 commands and you‘re ready to tag and roll.

Install

svn 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>

Reference

Documentation: 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.
Money_dollar moneywill