<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Ruby on Rails articles</title>
  <link type="application/atom+xml" rel="self" href="http://ruby-on-rails.groups.wuyasea.com/b1ogs/4/articles.xml"/>
  <link type="text/html" rel="alternate" href="http://ruby-on-rails.groups.wuyasea.com/b1ogs/4/articles"/>
  <language>en-us</language>
  <entry>
    <title>facebook app for newbies</title>
    <link type="text/html" rel="alternate" href="/articles/facebook-app-for-newbies/77"/>
    <updated>Tue, 18 Nov 2008 05:12:39 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">very detailed &lt;a href="http://rfacebook.wordpress.com/2008/01/10/tutorial/"&gt;article&lt;/a&gt; on how to create facebook app using RoR. very nice, indeed.&lt;br /&gt;
&lt;br /&gt;
found it through google terms: "rails facebook app tutorial"</content>
  </entry>
  <entry>
    <title>double your mysql integer column capacity</title>
    <link type="text/html" rel="alternate" href="/articles/double-your-mysql-integer-column-capacity/73"/>
    <updated>Sun, 05 Oct 2008 00:42:48 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">By default, rails' migration create signed integer columns, which accept both positive and negative values. But in db design, 99% of time integer are used for storing foreign keys. by creating a plugin that override the mysql adapter, all integer column are automatically created with unsigned flag, so you gain twice the id capacity. sweet.&lt;br /&gt;
&lt;br /&gt;
if you do want integer column with negative values, use &lt;strong&gt;:signed_int&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
module ActiveRecord
  module ConnectionAdapters
    class MysqlAdapter
      # make pk unsigned
      NATIVE_DATABASE_TYPES = {
        :primary_key =&gt; "int(11) unsigned DEFAULT NULL auto_increment PRIMARY KEY".freeze,
        :string      =&gt; { :name =&gt; "varchar", :limit =&gt; 255 },
        :text        =&gt; { :name =&gt; "text" },
        :integer     =&gt; { :name =&gt; "int", :limit =&gt; 4 },
        :signed_int  =&gt; { :name =&gt; "int", :limit =&gt; 4 },
        :float       =&gt; { :name =&gt; "float" },
        :decimal     =&gt; { :name =&gt; "decimal" },
        :datetime    =&gt; { :name =&gt; "datetime" },
        :timestamp   =&gt; { :name =&gt; "datetime" },
        :time        =&gt; { :name =&gt; "time" },
        :date        =&gt; { :name =&gt; "date" },
        :binary      =&gt; { :name =&gt; "blob" },
        :boolean     =&gt; { :name =&gt; "tinyint", :limit =&gt; 1 }
      }
      
      # Maps logical Rails types to MySQL-specific data types.
      # by default, all integer type are unsigned, unless you use :signed_int in migration.
      #
      # http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
      def type_to_sql(type, limit = nil, precision = nil, scale = nil)
        return super unless type.to_s == 'integer' or type.to_s == 'signed_int' 

        result = case limit
        when 1; 'tinyint'
        when 2; 'smallint'
        when 3; 'mediumint'
        when nil, 4, 11; 'int(11)'  # compatibility with MySQL default
        when 5..8; 'bigint'
        else raise(ActiveRecordError, "No integer type has byte size #{limit}")
        end
        
        result += " unsigned" unless type.to_s == 'signed_int'
        result
      end      
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;</content>
  </entry>
  <entry>
    <title>plugin sets relative session expire time</title>
    <link type="text/html" rel="alternate" href="/articles/plugin-sets-relative-session-expire-time/59"/>
    <updated>Sat, 12 Jul 2008 19:51:17 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">This &lt;a href="http://blog.codahale.com/2006/04/08/dynamic-session-expiration-times-with-rails/" target="_blank"&gt;plugin&lt;/a&gt; sets the session cookie expiration in relative time, not fixed time as default rails does, very nice.&lt;br /&gt;
&lt;br /&gt;
</content>
  </entry>
  <entry>
    <title>Asynchronous Processing (messaging) with Ruby on Rails</title>
    <link type="text/html" rel="alternate" href="/articles/asynchronous-processing-messaging-with-ruby-on-rails/55"/>
    <updated>Thu, 26 Jun 2008 17:48:23 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">meat from &lt;a href="http://www.slideshare.net/jondahl/asynchronous-processing-with-ruby-on-rails-railsconf-2008-443159/"&gt;slides&lt;/a&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;General purpose: &lt;a href="http://codeforpeople.rubyforge.org/svn/bj/trunk/"&gt;Bj&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Distributed processing: &lt;a href="http://sqs.rubyforge.org/"&gt;SQS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Speed + scalability: &lt;a href="http://rubyforge.org/projects/starling/"&gt;Starling&lt;/a&gt;, &lt;a href="http://svn.playtype.net/plugins/workling/README"&gt;Workling&lt;/a&gt; (workling &lt;a href="http://playtype.net/past/2008/2/6/starling_and_asynchrous_tasks_in_ruby_on_rails/"&gt;article&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://github.com/ncr/background-fu/tree/master"&gt;background-fu&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
workling's &lt;a href="http://svn.playtype.net/plugins/workling/README"&gt;readme&lt;/a&gt; pretty much blasted all its alternatives as crap. hehe.&lt;br /&gt;
&lt;br /&gt;
and of course ror's &lt;a href="http://wiki.rubyonrails.org/rails/pages/HowToRunBackgroundJobsInRails"&gt;wiki page&lt;/a&gt;.&lt;br /&gt;
</content>
  </entry>
  <entry>
    <title>What's new in Rails 2.1</title>
    <link type="text/html" rel="alternate" href="/articles/what-s-new-in-rails-2-1/54"/>
    <updated>Wed, 25 Jun 2008 18:56:42 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">all in this &lt;a href="http://www.nomedojogo.com/livro/carlosbrando-rubyonrails21_en.pdf" target="_blank"&gt;PDF&lt;/a&gt;</content>
  </entry>
  <entry>
    <title>starting with GIT</title>
    <link type="text/html" rel="alternate" href="/articles/starting-with-git/51"/>
    <updated>Thu, 19 Jun 2008 01:10:13 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">&lt;a href="http://www-cs-students.stanford.edu/~blynn/gitmagic/index.html"&gt;Git magic&lt;/a&gt;, a very comprehensive tutorial, almost like SVN's redbook.</content>
  </entry>
  <entry>
    <title>rails performance development</title>
    <link type="text/html" rel="alternate" href="/articles/rails-performance-development/45"/>
    <updated>Wed, 18 Jun 2008 19:29:12 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">&lt;a href="http://wiki.rubyonrails.org/rails/pages/HowToStressOrLoadTest"&gt;Ruby on Rails wiki page&lt;/a&gt;
&lt;br /&gt;
&lt;h3&gt;tools&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://railsbench.rubyforge.org/" target="_blank"&gt;http://railsbench.rubyforge.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://rails-analyzer.rubyforge.org/" target="_blank"&gt;http://rails-analyzer.rubyforge.org/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;articles&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://onrails.org/articles/2007/08/31/monitoring-rails-performance-with-munin-and-a-mongrel" target="_blank"&gt;Customize munin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://cfis.savagexi.com/articles/2007/07/10/how-to-profile-your-rails-application" target="_blank"&gt;tutorial on ruby-prof&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://nubyonrails.com/articles/a-hodel-3000-compliant-logger-for-the-rest-of-us" target="_blank"&gt;Hodel 3000 logger&lt;/a&gt; works with pl_analyze, rails default logger doesn't. :(&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
</content>
  </entry>
  <entry>
    <title>how to freeze rails</title>
    <link type="text/html" rel="alternate" href="/articles/how-to-freeze-rails/40"/>
    <updated>Mon, 10 Mar 2008 01:41:19 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">upgrading this app, but there're many other old apps still on rails 1.2.x. so I need to freeze rails for this app. way to do it is to&lt;br /&gt;
&lt;pre&gt;&lt;code class="console"&gt;rake rails:freeze:edge TAG=rel_2-0-2&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
you can lookup rails edge revision and tag numbers from &lt;a href="http://svn.rubyonrails.org/rails"&gt;rails' svn&lt;/a&gt;</content>
  </entry>
  <entry>
    <title>Keeping up with DHH</title>
    <link type="text/html" rel="alternate" href="/articles/keeping-up-with-dhh/33"/>
    <updated>Thu, 03 Jan 2008 14:32:16 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">rails sure evolves fast, now upto version 2.0.2. But I still have boat load of apps running on 1.2.x, spend quite sometime to update all the code and lock down the rails gem version to pre 2, so I can upgrade to latest rails for new apps. &lt;br /&gt;
&lt;br /&gt;
It's sure hard to keep up with DHH.&lt;br /&gt;
&lt;br /&gt;
If you've put "RAILS_GEM_VERSION = '1.2.5' unless defined? RAILS_GEM_VERSION" or frozen rails gem into your old app to 1.2.5 or 1.2.6, and when you run script/server, and get cryptic error like &lt;br /&gt;
&lt;pre&gt;&lt;code&gt;/usr/lib/ruby/site_ruby/1.8/rubygems.rb:246:in `activate': 
can't activate activesupport (= 2.0.2), already activated activesupport-1.4.4] (Gem::Exception)&lt;/code&gt;&lt;/pre&gt;
Most likely you're missing some gem. run script/console to find the missing gems.&lt;br /&gt;
&lt;br /&gt;
Better solution is to allow your rail apps to define all gems dependencies, and install it automatically.</content>
  </entry>
  <entry>
    <title>Rails 2 is near</title>
    <link type="text/html" rel="alternate" href="/articles/rails-2-is-near/30"/>
    <updated>Thu, 15 Nov 2007 02:36:35 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">On Nov 9th, David announced the availability of Rails 2 RC 1. Time sure flies.&lt;br /&gt;
&lt;br /&gt;
To see notable features in rails 2, check out &lt;a href="http://weblog.rubyonrails.org/2007/9/30/rails-2-0-0-preview-release"&gt;RoR blog&lt;/a&gt;. </content>
  </entry>
  <entry>
    <title>merb is da bomb!</title>
    <link type="text/html" rel="alternate" href="/articles/merb-is-da-bomb/29"/>
    <updated>Thu, 29 Nov 2007 15:34:11 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">Today I discovered &lt;a href="http://www.merbivore.com" target="_blank"&gt;Merb&lt;/a&gt;, and it definitely is da bomb class stuff!&lt;br /&gt;
&lt;br /&gt;
What is it? It's a rails like MVC framework without the sucky parts.&lt;br /&gt;
&lt;br /&gt;
The problem with rails is, although convention over configuration is generally a good thing, but sometimes it's hard to draw the line where it is. Merb don't do lots of things for you automatically like rails, so you have the freedom to do things in your own unique way.  &lt;br /&gt;
&lt;br /&gt;
Notable features of merbs are:&lt;br /&gt;
&lt;h3&gt;Pluggable ORM&lt;/h3&gt;
When you generate a new app, it doesn't assume you're using a DB. so merb can be used to create app without DB need, and server management frontend, cron job admin, etc. Even if you need to use ORM, you have the choice to use activereord, or other ORM I've never heard of, like Datamapper, Sequel.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Manual rendering&lt;/h3&gt;
Rails' action automatically calls render method for you. This pose some problems, you can't render multiple times or you get double render exception; you can't have nested layout, although people did create nested_layout plugin to work it around. &lt;br /&gt;
&lt;br /&gt;
In merb, you have to call render manually. which just returns the output text as result. want nested layout? then render with different layouts as many times as you want, in situations like you want to provide theme support. As said in ancient Chinese proverb, &#36827;&#19968;&#27493;&#65292;&#23665;&#31351;&#27700;&#23613;&#65307;&#36864;&#19968;&#27493;&#65292;&#28023;&#38420;&#22825;&#31354;&#12290;(One step forward, you're stuck in nowhere; one step back, there's world of possibilities).&lt;br /&gt;
&lt;br /&gt;
Rails has something similar method called render_to_string, in merb, it's first class citizen.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Plugin dependency&lt;/h3&gt;
If you've been working with rails for awhile, then you know how much rails plugin suck. There's no plugin dependency, I see people either copy all plugin B code into plugin A if A needs B, or rename plugins since rails loads plugins alphabetically. Note, rails do allow you to configure plugin loading order now. &lt;br /&gt;
&lt;br /&gt;
In merb, plugin is just a gem, multiple versions and dependency are all built in.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Summary&lt;/h3&gt;
To give credit to rails, merb did "steal" lot of code from rails, but the framwork has vastly different approach. Merb tries to stay agile, a micro framework, yet provides support to allow component builders to add functionality easily.&lt;br /&gt;
&lt;br /&gt;
Merb's tool and coding syntax usage are very similar to rails, so rails developer should be able to learn and use it without much difficulty.&lt;br /&gt;
&lt;br /&gt;
For all rails developers, it's definitely something to dive into.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;trivia&lt;/h3&gt;
One thing intrigues me is that merb is on the domain merbivore.com, not merb.com. After some poking around, then I found out merb.com's owner wanted either $25000 lum sum or $500 monthly rent for use of the domain. No love for open source. :(</content>
  </entry>
  <entry>
    <title>more problem and hacks in theme_support plugin</title>
    <link type="text/html" rel="alternate" href="/articles/more-problem-and-hacks-in-theme-support-plugin/27"/>
    <updated>Tue, 04 Dec 2007 01:25:13 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">Looks like theme_support doesn't work if route ends with an extension, like "/blog/rss.rxml", nor does it work with namespaced action mailer templates. So I had to change the actionview_ex.rb quite a bit to make it to work. here the updated code:&lt;br /&gt;
&lt;br /&gt;
Changes are:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;added "../.." for namespaced mailer template&lt;/li&gt;
&lt;li&gt;do not pick_template_extension if extension exists in route.&lt;/li&gt;
&lt;li&gt;Move __render_file() into try catch block.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;h3&gt;Updates, ActionView::TemplateError check&lt;/h3&gt;
cool, somebody actually read my stuff! well, yes, above hack returns a very bad exception message if you have a error anywhere in ruby code or in rhtml template. Below is the code I should've put up earlier, just never got time to do it. Now here it is.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;# Extending &lt;tt&gt;ActionView::Base&lt;/tt&gt; to support rendering themes
#
module ActionView
   
   # Extending &lt;tt&gt;ActionView::Base&lt;/tt&gt; to support rendering themes
   class Base
      alias_method :__render_file, :render_file

      # Overrides the default &lt;tt&gt;Base#render_file&lt;/tt&gt; to allow theme-specific views
      def render_file(template_path, use_full_path = true, local_assigns = {})        
         search_path = [
            &lt;strong&gt;# "../themes/#{controller.current_theme}/views/",       # I don't use components&lt;/strong&gt;
            "../../themes/#{controller.current_theme}/views/",    # for normal views
            "../../themes/#{controller.current_theme}/",          # for layouts
            # "../../../themes/#{controller.current_theme}/views/", # for mailer views, not using now.
            &lt;strong&gt;"",                                                   # fallback&lt;/strong&gt;
            "../",                                                # Mailer fallback
            &lt;strong&gt;"../../"                                              # namespaced Mailer fallback&lt;/strong&gt;
         ]
         
         if use_full_path
            search_path.each do |prefix|
               theme_path = prefix + template_path
               begin
                  &lt;strong&gt;template_path_without_extension, template_extension = path_and_extension(theme_path)
                  template_extension = pick_template_extension(theme_path).to_s if !template_extension&lt;/strong&gt;

                  # Prevent .rhtml (or any other template type) if force_liquid == true
                  if force_liquid? and
                     template_extension.to_s != 'liquid' and 
                     prefix != '.'
                     raise ThemeError.new("Template '#{template_path}' must be a liquid document")
                  end
                  local_assigns['active_theme'] = get_current_theme(local_assigns)
                  return __render_file(theme_path, use_full_path, local_assigns)
&lt;strong&gt;               rescue ActionView::TemplateError =&gt; err
                   next if err.message =~ /No such file or directory/            # for rxml templates
                   raise err&lt;/strong&gt;
               rescue ActionView::ActionViewError =&gt; err
                   next
               rescue ThemeError =&gt; err
                  # Should it raise an exception, or just call 'next' and revert to
                  # the default template?
                  raise err
               end

            end
            raise ActionViewError, "No rhtml, rxml, or delegate template found for #{template_path} in #{@base_path}"
         else
            __render_file(template_path, use_full_path, local_assigns)
         end
      end
      
   private
   
    def force_liquid?
      unless controller.nil?
        if controller.respond_to?('force_liquid_template')
          controller.force_liquid_template
        end
      else
        false
      end
    end

    def get_current_theme(local_assigns)
      unless controller.nil?
        if controller.respond_to?('current_theme')
          return controller.current_theme || false
        end
      end
      # Used with ActionMailers
      if local_assigns.include? :current_theme 
        return local_assigns.delete :current_theme
      end
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;</content>
  </entry>
  <entry>
    <title>Add theme support to rails app</title>
    <link type="text/html" rel="alternate" href="/articles/add-theme-support-to-rails-app/25"/>
    <updated>Wed, 24 Oct 2007 18:25:10 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">If you want to add theme support to your rails app, easiest way is to use Matt McCray's &lt;a href="http://mattmccray.com/svn/rails/plugins/theme_support/" target="_blank"&gt;theme_support&lt;/a&gt; plugin. just do "script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support/" to get it.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;1. The Problem&lt;/h3&gt;
But it doesn't work out of box. when you start the server, you'll get error like:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;theme_app/vendor/plugins/theme_support/lib/patches/routeset_ex.rb:27:in `create_theme_routes': 
undefined method `named_route' for #&amp;lt;actioncontroller::routing::routeset:0xb74da758&gt; (NoMethodError)
        from theme_app/vendor/plugins/theme_support/lib/patches/routeset_ex.rb:13:in `draw'
        from ./script/../config/../config/routes.rb:1
        ...
&lt;/code&gt;&lt;/pre&gt;
Since the last update of the plugin was April 2006, and now is Oct 2007, so changes of rails internal must made the plugin incompatible. On Matt's &lt;a href="http://mattmccray.com/archive/2006/04/09/Rails_Theme_Support_Plugin_v_1" target="_blank"&gt;blog&lt;/a&gt;, someone suggested a &lt;a href="http://pastie.caboo.se/9651" target="_blank"&gt;workaround&lt;/a&gt;, to change the route function calls in plugin's route patch (lib/patch/routeset_ex.rb). But I choose to take a more conservative approach, not to patch routing at all.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;2. The Fix&lt;/h3&gt;
So here are the changes I made to the plugin to make it futureproof.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Disable routing patch.&lt;/strong&gt;  comment out "require 'patches/routeset_ex'" line in theme_support/init.rb&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add theme routes into config/routes.rb&lt;/strong&gt; &lt;pre&gt;&lt;code&gt;
   map.theme_images "/themes/:theme/images/*filename", :controller=&gt;'theme', :action=&gt;'images'
   map.theme_stylesheets "/themes/:theme/stylesheets/*filename", :controller=&gt;'theme', :action=&gt;'stylesheets'
   map.theme_javascript "/themes/:theme/javascript/*filename", :controller=&gt;'theme', :action=&gt;'javascript'

   map.connect "/themes/*whatever", :controller=&gt;'theme', :action=&gt;'error'&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Now start the server, and it shall work.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;3. Usage&lt;/h3&gt;
To create a new theme, do "script/generate theme YOUR_THEME_NAME", see plugin's readme for more usage.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;4. Related pages&lt;/h3&gt;
&lt;a href="http://code.google.com/p/rails-multisite/" target="_blank"&gt;http://code.google.com/p/rails-multisite/&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://wiki.rubyonrails.org/rails/pages/View+Extensions" target="_blank"&gt;http://wiki.rubyonrails.org/rails/pages/View+Extensions&lt;/a&gt; if it's not down. </content>
  </entry>
  <entry>
    <title>How to config plugin classes in dev/test/prod env file</title>
    <link type="text/html" rel="alternate" href="/articles/how-to-config-plugin-classes-in-dev-test-prod-env-file/18"/>
    <updated>Tue, 16 Oct 2007 23:02:59 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">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. &lt;br /&gt;
&lt;br /&gt;
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 &lt;br /&gt;
&lt;code&gt;/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)&lt;/code&gt;&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
The solution is quite simple, just do it afterwards. &lt;br /&gt;
&lt;br /&gt;
at the end of my environment.rb, just add &lt;code&gt;require File.join(File.dirname(__FILE__), "environments/#{ENV['RAILS_ENV'] || 'test'}_post_init")&lt;/code&gt;&lt;br /&gt;
"|| '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&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
</content>
  </entry>
  <entry>
    <title>Use Capistrano to deploy your own private gem.</title>
    <link type="text/html" rel="alternate" href="/articles/use-capistrano-to-deploy-your-own-private-gem/16"/>
    <updated>Tue, 16 Oct 2007 23:02:59 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">Jeffrey Allan Hardy has written a &lt;a href="http://www.quotedprintable.com/2007/3/16/installing-gems-with-capistrano"&gt;guide&lt;/a&gt; about how to deploy public gems. Now what if you have your own private gems, and you like to deploy them as easily as deploying a rails app, what do you do? Use capistrano. This articles shows how to use Capistrano to deploy your own private gem. &lt;br /&gt;
&lt;br /&gt;
You gem should have existing tasks called "gem" and "install_gem", you can get them automatically if you use &lt;a href="http://newgem.rubyforge.org/"&gt;new_gem&lt;/a&gt; to generate your new gem (that's a mouthful). On another thought, new_gem should be renamed to "gem_gen", sounds alot cooler and less confusing.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;1. Write cap tasks&lt;/h3&gt;
in your gem project folder, create 2 files, "capfile", and "gem_deploy.rb".&lt;br /&gt;
&lt;br /&gt;
capfile should be looks like this:&lt;br /&gt;
&lt;code&gt;load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'gem_deploy'&lt;/code&gt;&lt;br /&gt;
and gem_deploy.rb should have following&lt;br /&gt;
&lt;code&gt;# to deploy this gem, check out first, then
# 
# cap deploy:setup
# cap deploy:update_code
# 
# 
# === reference ===
# install standard gem
# http://www.quotedprintable.com/2007/3/16/installing-gems-with-capistrano

#ssh_options[:verbose] = :debug 
set :synchronous_connect, true    # without this, upload task will hang

role :lib, "mysite.com"

set :application, "my_cool_gem"
set :repository,  "svn://my/gems/#{application}/trunk"
set :deploy_to, "/home/dorren/temp/#{application}"
set :user, "dorren"
set :deploy_via, :copy


namespace :deploy do
  desc "build and install gem by using rake"
  task :finalize_update do    
    # -S accepts password from stdin instead of terminal, see man sudo"
    cmd = "-S ls &amp;&amp; cd #{current_release} &amp;&amp; rake gem &amp;&amp; rake install_gem"
    sudo cmd do |channel, stream, data|
      print data if stream == :out
      channel.send_data($stdin.gets) if data =~ /^&gt;\s/
    end
  end
end
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;2. Deploy&lt;/h3&gt;
&lt;code class="console"&gt;cap deploy:setup&lt;/code&gt;will setup temporary staging folder.&lt;br /&gt;
&lt;code class="console"&gt;cap deploy:update_code&lt;/code&gt; will install the gem.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;3. troubleshooting&lt;/h3&gt;
Q: I get error, "&amp;lt;me&gt; is not in the sudoers file." when deploying.&lt;br /&gt;
A: I just added myself into the sudoer group which resolved the problem. </content>
  </entry>
  <entry>
    <title>Same problem, 17 lines in java, 3 lines in ruby</title>
    <link type="text/html" rel="alternate" href="/articles/same-problem-17-lines-in-java-3-lines-in-ruby/12"/>
    <updated>Tue, 16 Oct 2007 23:02:59 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">write a program to produce the following output:&lt;br /&gt;
1 A&lt;br /&gt;
2 BB&lt;br /&gt;
3 CCC&lt;br /&gt;
......&lt;br /&gt;
25 YYYYYYYYYYYYYYYYYYYYYYYYY&lt;br /&gt;
26 ZZZZZZZZZZZZZZZZZZZZZZZZZZ&lt;br /&gt;
27 012345678901234567890123456&lt;br /&gt;
&lt;br /&gt;
In java, this is probably what most of programmers do:&lt;br /&gt;
&lt;code&gt;
 public class Text {
  public static void main(String args[]) {
    int x = 0;
    for (char c = 'A'; c &amp;lt;= 'Z'; c++) {
      x++;
      System.out.print(x + " ");
      for (int i = 0; i &amp;lt; x; i++) {
        System.out.print( c );
      }
      System.out.println();
    }
    System.out.print(x + 1 + " ");
    for (int i = 0; i &amp;lt;= x; i++) {
      System.out.print(i % 10);
    }
  }
} 
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
In ruby it only takes 3 lines&lt;br /&gt;
&lt;code&gt;n = ?A - 1
(1..26).each do |i| puts i.to_s + " " + (i+n).chr*i end
puts "27 " + (0..27).collect{|i| i%10}.to_s
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Some rubyism for people not familiar with ruby.&lt;br /&gt;
&lt;code&gt;# some ruby language functions
#
# ?&amp;lt;x&gt; return the ASCII code of the character
# ?A =&gt; 65
# ?B =&gt; 66
# ?\n =&gt; 10 backspace ASCII code is 10
#
#
# &amp;lt;n&gt;.chr returns the character from given ASCII code
# 65.chr =&gt; "A"
# 66.chr =&gt; "B"
# 10.chr =&gt; "\n"
#
#
# &amp;lt;str&gt;*&amp;lt;n&gt; multiplies given string n times.
# "ABC"*2 =&gt; ABCABC
#
#
# ruby use "#{var}" syntax to print variable in a string
# x = "abc"
# puts "output: #{x}" =&gt; "output: abc" 
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
But you can combine the character and number printing together in one loop. try it.</content>
  </entry>
  <entry>
    <title>Be_taggable, the commercial ;)</title>
    <link type="text/html" rel="alternate" href="/articles/be-taggable-the-commercial/10"/>
    <updated>Tue, 16 Oct 2007 23:02:59 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">Be_Taggable, the commercial ;)&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;
=== 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 &lt;a href="http://railers.rubyforge.org/be_taggable"&gt;http://railers.rubyforge.org/be_taggable&lt;/a&gt; *
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
Many thanks to acts_as_taggable. be_taggable becomes small by standing on the shoulder of acts_as_taggable giant.</content>
  </entry>
  <entry>
    <title>Be_taggable plugin, 1/10th size of acts_as_taggable</title>
    <link type="text/html" rel="alternate" href="/articles/be-taggable-plugin-1-10th-size-of-acts-as-taggable/8"/>
    <updated>Tue, 16 Oct 2007 23:02:59 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">&lt;h3&gt;Meet be_taggable plugin&lt;/h3&gt;
&lt;br /&gt;
Originally I planned to use the &lt;a href="http://rubyforge.org/projects/taggable/"&gt;Acts_as_taggable&lt;/a&gt; gem, then i check out the code, and just can't accept how can simple tagging takes 675 lines.&lt;br /&gt;
&lt;br /&gt;
So by "borrowing" code from that gem, I've created be_taggable plugin, major improvements:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;The name Be_taggable is 5 letters less, or 31.25% more efficient.&lt;/li&gt;
&lt;li&gt;BeTaggable module weights 67 lines, compare to 675 lines, a whopping 90% improvement.&lt;/li&gt;
&lt;li&gt;Built in tags_cache column to reduce DB traffic.&lt;/li&gt;
&lt;li&gt;Simple installation, run 3 commands and you&#8216;re ready to tag and roll.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Install&lt;/h3&gt;
&lt;code class="console"&gt;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
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Usage&lt;/h3&gt;
&lt;code&gt;  Class TestBook
    be_taggable  # Mark your class be_taggable.
    ...
  end

  book = TestBook.create(:name =&gt; "AWDWR")
  book.tag("programming, rails")       # 2 tags added
  book.tag("agile,       rails")       # "programming" removed,
                                         "agile"       added,
                                         "rails"       untouched.

  hash = TestBook.tags_count     # {"rails" =&gt; 1, "agile" =&gt; 1}

  book.tag("")                         # remove all tags.

  TestBook.find_tagged_with("rails")  # return list of matching book objects.
  TestBook.find_tagged_with("rails", :offset =&gt; 20, :limit =&gt; 10)  # search with options.
&lt;/code&gt;&lt;br /&gt;
and in template&lt;br /&gt;
&lt;code&gt;
# To display model&#8216;s tags from tags_cache column.

      &amp;lt;% for tag in YAML::load(article.tags_cache) %&amp;gt;
        &amp;lt;%= link_to(tag, tagged_articles_path(tag))  # assume route exists %&amp;gt;
      &amp;lt;% end -%&amp;gt;


# To show tag cloud
    &amp;lt;table&amp;gt;
    &amp;lt;% Article.tags_count.sort.each{|pair| %&amp;gt;
      &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;%= link_to(pair[0], tagged_articles_path(pair[0])) %&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;%= pair[1] # count %&amp;gt;&amp;lt;/td&amp;gt;
      &amp;lt;/tr&amp;gt;
    &amp;lt;% } %&amp;gt;
    &amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Reference&lt;/h3&gt;
Documentation: &lt;a href="http://railers.rubyforge.org/be_taggable/"&gt;http://railers.rubyforge.org/be_taggable/&lt;/a&gt;
&lt;br /&gt;
Code: &lt;b&gt;svn export http://railers.rubyforge.org/svn/plugins/trunk/be_taggable&lt;/b&gt;</content>
  </entry>
  <entry>
    <title>Simple code for playing card </title>
    <link type="text/html" rel="alternate" href="/articles/simple-code-for-playing-card/6"/>
    <updated>Tue, 16 Oct 2007 23:02:59 -0000</updated>
    <author>
      <name>dorren</name>
    </author>
    <content type="html">Simple code to implement playing card. In case you want to build an online casino with Ruby on Rails, you got a head start. :)&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt;class Deck
   COLOR = %w(S H D C)  # Spade Heart Diamond Club
   POINT = %w(2 3 4 5 6 7 8 9 10 J Q K A)
   attr_accessor :cards
   
   def initialize
     @cards = []
     COLOR.each{|c| 
       POINT.each{|p| 
         @cards &amp;lt;&amp;lt; Card.new(COLOR.index(c), POINT.index(p))
       }
     }
     self
   end
   
   def shuffle
     52.times{|i| r = rand(52); @cards[i], @cards[r] = @cards[r], @cards[i]}
   end
   
   def sort
     @cards.sort!{|x, y| x &amp;lt;=&gt; y}
   end
   
   def to_s
     @cards.collect{|c| "#{COLOR[c.color]} #{POINT[c.point]}"}.join("\n")
   end
end

class Card
  attr_accessor :color, :point
  def initialize(color, point)
    @color, @point = color, point
  end
  
  def &amp;lt;=&gt;(obj)
    color == obj.color ? obj.point &amp;lt;=&gt; point : color &amp;lt;=&gt; obj.color
  end
end

deck = Deck.new
deck.shuffle
puts "\n----shuffle-----\n#{deck}"
deck.sort
puts "\n----sort-----\n#{deck}"&lt;/code&gt;</content>
  </entry>
</feed>
