<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-38601396</atom:id><lastBuildDate>Fri, 29 May 2026 15:01:30 +0000</lastBuildDate><category>rhg</category><category>rails</category><category>gems</category><category>activerecord</category><category>plugins</category><category>deployment</category><category>migrations</category><category>ruby</category><category>plugem</category><category>acts_as</category><category>blog</category><category>db</category><category>jruby</category><category>plugin</category><category>revolutionhealth</category><category>tips</category><category>db slaves</category><category>dry</category><category>enhanced_migrations</category><category>facade</category><category>javascript</category><category>jmx</category><category>performance</category><category>readonly</category><category>recipes</category><category>resource</category><category>rhgcontrol</category><category>ajax</category><category>caching</category><category>capistrano</category><category>captcha</category><category>code</category><category>code digest</category><category>config</category><category>controller</category><category>digest</category><category>edge</category><category>esi</category><category>fabric</category><category>failure</category><category>fun</category><category>helpers</category><category>indexing</category><category>layouts</category><category>metaprogramming</category><category>metics</category><category>mocks</category><category>openssl</category><category>partials</category><category>pastebin</category><category>polymorphic</category><category>profiling</category><category>refactoring</category><category>rhtml</category><category>search</category><category>threadsafe_benchmark</category><category>tod</category><category>views</category><title>Revolution On Rails</title><description></description><link>http://revolutiononrails.blogspot.com/</link><managingEditor>noreply@blogger.com (Jeffrey)</managingEditor><generator>Blogger</generator><openSearch:totalResults>57</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-4674740310760348743</guid><pubDate>Wed, 09 Jul 2008 17:10:00 +0000</pubDate><atom:updated>2008-07-09T10:27:34.094-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">activerecord</category><category domain="http://www.blogger.com/atom/ns#">blog</category><category domain="http://www.blogger.com/atom/ns#">gems</category><category domain="http://www.blogger.com/atom/ns#">indexing</category><category domain="http://www.blogger.com/atom/ns#">search</category><title>[PLUGIN RELEASE] ActsAsOverflowable</title><description>&lt;span style=&quot;color: rgb(0, 0, 0);font-family:verdana;font-size:100%;&quot;  &gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;acts_as_overflowable&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;Written by Nicholas Lega&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== DESCRIPTION:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Allows a column to overflow data into a secondary column if the data size exceeds the character limit. This is useful for fast indexing.&lt;br /&gt;&lt;br /&gt;Instead of trying to index text blobs, you can specify a varchar column to be used for indexing.  Any characters that do not fit into the base column will be automatically saved into or retrieved from an overflow field.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== SYNOPSIS:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create overflow column migration:&lt;br /&gt;&lt;div style=&quot;background-color: rgb(204, 204, 255);&quot;&gt;&lt;pre&gt;&lt;br /&gt; class CreateOverflowModels &lt; ActiveRecord::Migration   &lt;br /&gt;   def self.up         &lt;br /&gt;     create_table :overflows do |t|       &lt;br /&gt;       t.integer :overflowable_id       &lt;br /&gt;       t.string :overflowable_type       &lt;br /&gt;       t.string :overflow       &lt;br /&gt;       t.timestamps     &lt;br /&gt;     end&lt;br /&gt;&lt;br /&gt;     add_column(:my_class_that_uses_overflows,&lt;br /&gt;                :has_overflow,                 &lt;br /&gt;                :boolean)     &lt;br /&gt;&lt;br /&gt;     add_column(:my_class_that_uses_overflows,                 &lt;br /&gt;                :overflowable_text,                 &lt;br /&gt;                :string,                 &lt;br /&gt;                :limit =&gt; 255)&lt;br /&gt;   end&lt;br /&gt;&lt;br /&gt;   def self.down&lt;br /&gt;     drop_table :overflows&lt;br /&gt;&lt;br /&gt;     remove_column(:my_class_that_uses_overflows,&lt;br /&gt;                   :has_overflow)&lt;br /&gt;&lt;br /&gt;     remove_column(:my_class_that_uses_overflows, &lt;br /&gt;                   :overflowable_text)&lt;br /&gt;   end&lt;br /&gt; end&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Add to model:&lt;br /&gt;&lt;div style=&quot;background-color: rgb(204, 204, 255);&quot;&gt;&lt;pre&gt;&lt;br /&gt; class MyClassThatUsesOverflow &lt; ActiveRecord::Base   &lt;br /&gt;   acts_as_overflowable :overflow_column =&gt; :overflowable_text,&lt;br /&gt;                        :overflow_limit =&gt; 255,&lt;br /&gt;                        :overflow_indicator =&gt; :has_overflow,&lt;br /&gt;                        :overflow_table =&gt; :overflows&lt;br /&gt; end&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;To get and set the value of the &quot;overflowable_text&quot; field as described in the test model, use:&lt;br /&gt;&lt;div style=&quot;background-color: rgb(204, 204, 255);&quot;&gt;&lt;pre&gt;&lt;br /&gt; # #{my_field_name_here}_with_overflow is the method name&lt;br /&gt; long_text = overflowable_obj.overflowable_text_with_overflow&lt;br /&gt;&lt;br /&gt; overflowable_obj.overflowable_text_with_overflow = very_long_text&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Simply using the getters and setters for &quot;overflowable_text&quot; without appending &quot;_with_overflow&quot; to the method name will return the fragment of the text contained in the base column.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== INSTALL:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sudo gem install revolutionhealth-acts_as_overflowable -s http://gems.github.com&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== SOURCE:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;http://github.com/revolutionhealth/acts_as_overflowable/tree/master&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);font-family:verdana;font-size:100%;&quot;  &gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== FEATURES/PROBLEMS:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;* Only tested on mysql and sqlite3&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 0);font-family:verdana;font-size:100%;&quot;  &gt;&lt;br /&gt;&lt;/span&gt;</description><link>http://revolutiononrails.blogspot.com/2008/07/plugin-release-actsasoverflowable.html</link><author>noreply@blogger.com (John Constable)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-4478265987766687315</guid><pubDate>Thu, 19 Jun 2008 16:21:00 +0000</pubDate><atom:updated>2008-06-19T10:04:26.648-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">activerecord</category><category domain="http://www.blogger.com/atom/ns#">blog</category><category domain="http://www.blogger.com/atom/ns#">gems</category><category domain="http://www.blogger.com/atom/ns#">recipes</category><category domain="http://www.blogger.com/atom/ns#">resource</category><title>[PLUGIN RELEASE] ActsAsSeoFriendly</title><description>&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;ActsAsSeoFriendly&lt;br /&gt;&lt;br /&gt;== DESCRIPTION:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create an SEO friendly field for a model automatically based on a given field.&lt;br /&gt;&lt;br /&gt;So if you have a Blogs model, and you would like create an SEO friendly version&lt;br /&gt;of the &#39;title&#39; field, you would just add this to your model and then be able to&lt;br /&gt;use the SEO friendly id as the unique id to the resource.  The plugin will only&lt;br /&gt;append an integer to the SEO id if there is a collision.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;== SYNOPSIS:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create seo column migration:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt;class CreateSeoTestModels &lt; ActiveRecord::Migration&lt;br /&gt;  def self.up&lt;br /&gt;    create_table :seo_test_models do |t|&lt;br /&gt;      t.string :name&lt;br /&gt;      t.timestamps&lt;br /&gt;    end&lt;br /&gt;  SeoTestModel.create_seo_friendly_column()&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def self.down&lt;br /&gt;  SeoTestModel.drop_seo_friendly_column()&lt;br /&gt;    drop_table :seo_test_models&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Add to model:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt; class SeoTestModel &lt; ActiveRecord::Base&lt;br /&gt;  acts_as_seo_friendly :resource_id =&gt; :name,&lt;br /&gt;              :seo_friendly_id_field =&gt; :seo_id, # default is :seo_friendly_id&lt;br /&gt;              :seo_friendly_id_limit =&gt; 100 # default is 50&lt;br /&gt; end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To lookup the resource in the controllers use:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt; SeoTestModel.find_by_seo_id(params[:id])&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== INSTALL:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sudo gem install revolutionhealth-acts_as_seo_friendly -s &lt;a href=&quot;http://gems.github.com/&quot;&gt;http://gems.github.com&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-family: georgia;&quot;&gt;== SOURCE:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href=&quot;http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master&quot;&gt;&lt;span style=&quot;font-family:georgia;&quot;&gt;  http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master&lt;/span&gt;   &lt;/a&gt;&lt;span style=&quot;font-family: georgia;font-family:georgia;&quot; &gt;&lt;a href=&quot;http://github.com/revolutionhealth/acts_as_seo_friendly/tree/master&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;To see the plugin in action see our recipes section, for example:&lt;/span&gt;  &lt;span style=&quot;font-family: georgia;font-family:georgia;&quot; &gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.revolutionhealth.com/recipes/thai-miang-khem-style-salad&quot;&gt;http://www.revolutionhealth.com/recipes/thai-miang-khem-style-salad&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;== FEATURES/PROBLEMS:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;* Only tested on mysql and sqlite3</description><link>http://revolutiononrails.blogspot.com/2008/06/plugin-release-actsasseofriendly.html</link><author>noreply@blogger.com (Jeffrey)</author><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-7195358482039521475</guid><pubDate>Thu, 13 Dec 2007 21:44:00 +0000</pubDate><atom:updated>2007-12-13T14:47:47.979-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">plugin</category><category domain="http://www.blogger.com/atom/ns#">threadsafe_benchmark</category><title>ThreadsafeBenchmark</title><description>When testing products such as services which need to be stress-tested prior to release, it&#39;s necessary to use multi-threading to get as close to real world usage as possible. This gem, though not intended to be a replacement for full-fledged testing suites such as &lt;a href=&quot;http://en.wikipedia.org/wiki/LoadRunner&quot;&gt;LoadRunner&lt;/a&gt;, can provide instantaneous results to facilitate TDD programming. To reduce the duplication of code, the gem utilizes Ruby&#39;s built-in Benchmark module for the base functionality while preventing the output from clobbering through the use of thread-specific IO buffers.&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;require &#39;threadsafe_benchmark&#39;&lt;br /&gt;include ThreadsafeBenchmark&lt;br /&gt;&lt;br /&gt;threads = []&lt;br /&gt;max_num = 5000&lt;br /&gt;&lt;br /&gt;5.to_i.times { |i|&lt;br /&gt; threads &amp;lt;&amp;lt; Thread.new(max_num) { |n|&lt;br /&gt;   threadsafe_bm(6) { |x|&lt;br /&gt;     x.report(&quot;for:&quot;)   { for i in 1..n; a = &quot;1&quot;; end }&lt;br /&gt;     x.report(&quot;times:&quot;) { n.times do   ; a = &quot;1&quot;; end }&lt;br /&gt;     x.report(&quot;upto:&quot;)  { 1.upto(n) do ; a = &quot;1&quot;; end }&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;threads.each { |t| t.join }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Using the standard Benchmark, the results would be printed haphazardly making it difficult to read and interpret. But ThreadsafeBenchmark cleans everything up giving us nicely laid out columns.&lt;br /&gt;&lt;br /&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;user&lt;/td&gt;&lt;td&gt;system&lt;/td&gt;&lt;td&gt;total&lt;/td&gt;&lt;td&gt;real&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;for&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002889)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;times&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002477)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;upto&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002479)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;for&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002401)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;times&lt;/td&gt;&lt;td&gt;0.010000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.010000&lt;/td&gt;&lt;td&gt;(  0.002586)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;upto&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002413)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;for&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002205)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;times&lt;/td&gt;&lt;td&gt;0.010000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.010000&lt;/td&gt;&lt;td&gt;(  0.002245)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;upto&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.002272)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;for&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.001822)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;times&lt;/td&gt;&lt;td&gt;0.010000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.010000&lt;/td&gt;&lt;td&gt;(  0.001958)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;upto&lt;/td&gt;&lt;td&gt;0.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;(  0.001943)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;for&lt;/td&gt;&lt;td&gt;0.010000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.010000&lt;/td&gt;&lt;td&gt;(  0.010090)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;times&lt;/td&gt;&lt;td&gt;0.010000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.010000&lt;/td&gt;&lt;td&gt;(  0.009225)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;upto&lt;/td&gt;&lt;td&gt;0.010000&lt;/td&gt;&lt;td&gt;.000000&lt;/td&gt;&lt;td&gt;.010000&lt;/td&gt;&lt;td&gt;(  0.007986)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;The &lt;a href=&quot;http://rubyforge.org/frs/download.php/29198/threadsafe_benchmark-1.0.0.gem&quot;&gt;gem&lt;/a&gt; and &lt;a href=&quot;http://rubyforge.org/frs/download.php/29200/threadsafe_benchmark-1.0.0.tgz&quot;&gt;source&lt;/a&gt; files are available at Rubyforge.</description><link>http://revolutiononrails.blogspot.com/2007/12/threadsafebenchmark.html</link><author>noreply@blogger.com (Sean)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-1883936140685574544</guid><pubDate>Tue, 06 Nov 2007 18:38:00 +0000</pubDate><atom:updated>2007-11-15T17:27:51.069-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">enhanced_migrations</category><category domain="http://www.blogger.com/atom/ns#">migrations</category><title>Enhanced Migrations v1.2.0</title><description>The original release of this highly useful plugin marked a turning point in collaborative Rails development by freeing the developer to commit their database migration without fear of having it ignored because of a higher placed migration number. This latest release includes some minor bug fixes plus a useful method for stepping through migrations one at a time without the need for copying and pasting long version numbers.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Fixed bug where an empty migrations_info table would create a non-parseable schema.rb.&lt;/li&gt;&lt;li&gt;Made plugin database independent.&lt;/li&gt;&lt;li&gt;Added capability to step through migrations using VERSION=[previous, next, first and last].&lt;/li&gt;&lt;li&gt;dump_schema_information now returns all migrations, not just latest (credit to &lt;a href=&quot;http://blog.teksol.info/2007/11/1/enhanced-migrations-plugin-enhancement&quot;&gt;François Beausolei&lt;/a&gt;).&lt;/li&gt;&lt;li&gt;Added tests which use SQLite and a task (enhanced_migrations:clean_sqlite_db) to help with testing.&lt;/li&gt;&lt;/ol&gt;As an example of item number three, consider the following situation. Using the enhanced migrations plugin, you&#39;ve just created a migration that adds a new table to your database. Upon running it, you discover that you used the wrong data type for a column. Rather than having to copy and paste the previous migration&#39;s version number, simply using &#39;previous&#39; in the VERSION number will now suffice.&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt;rake db:migrate VERSION=previous&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;This also works using &lt;code&gt;prev&lt;/code&gt; along with &lt;code&gt;next&lt;/code&gt;, &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; for their respective operations. Keep in mind that &lt;code&gt;first&lt;/code&gt; will go to the first migration and is not the same as &lt;code&gt;VERSION=0&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;Migrate as usual&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt;shell&gt; rake db:migrate&lt;br /&gt;== CreateRecipesTable: migrating ==============================================&lt;br /&gt;-- create_table(:recipes)&lt;br /&gt;-&gt; 0.0902s&lt;br /&gt;== CreateRecipesTable: migrated (0.0904s) =====================================&lt;br /&gt;&lt;br /&gt;== AddRecipesForUser1: migrating ==============================================&lt;br /&gt;-- execute(&quot;INSERT INTO recipes (name, owner) VALUES (&#39;Lemon Meringue Pie&#39;, &#39;user1&#39;)&quot;)&lt;br /&gt;-&gt; 0.3684s&lt;br /&gt;== AddRecipesForUser1: migrated (0.5302s) =====================================&lt;br /&gt;&lt;br /&gt;== AddRecipesForUser2: migrating ==============================================&lt;br /&gt;-- execute(&quot;INSERT INTO recipes (name, owner) VALUES (&#39;Steak and Kidney Pie&#39;, &#39;user2&#39;)&quot;)&lt;br /&gt;-&gt; 0.2574s&lt;br /&gt;== AddRecipesForUser2: migrated (0.3962s) =====================================&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Migrate to the previous version&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt;shell&gt; rake db:migrate VERSION=previous&lt;br /&gt;== AddRecipesForUser2: reverting ==============================================&lt;br /&gt;-- execute(&quot;DELETE FROM recipes WHERE owner = &#39;user2&#39;&quot;)&lt;br /&gt;-&gt; 0.4512s&lt;br /&gt;== AddRecipesForUser2: reverted (0.4516s) =====================================&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Migrate to the first version&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt;shell&gt; rake db:migrate VERSION=first&lt;br /&gt;== AddRecipesForUser1: reverting ==============================================&lt;br /&gt;-- execute(&quot;DELETE FROM recipes WHERE owner = &#39;user1&#39;&quot;)&lt;br /&gt;-&gt; 0.1676s&lt;br /&gt;== AddRecipesForUser1: reverted (0.1678s) =====================================&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Migrate another previous version, essentially the same as &lt;code&gt;VERSION=0&lt;/code&gt; since we are already at the first migration.&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;&lt;br /&gt;shell&gt; rake db:migrate VERSION=previous&lt;br /&gt;== CreateRecipesTable: reverting ==============================================&lt;br /&gt;-- drop_table(:recipes)&lt;br /&gt;-&gt; 0.1680s&lt;br /&gt;== CreateRecipesTable: reverted (0.1683s) =====================================&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;How to get&lt;/span&gt;&lt;br /&gt;Download the &lt;a href=&quot;http://rubyforge.org/frs/download.php/27985/enhanced_migrations-1.2.1.gem&quot;&gt;gem&lt;/a&gt; from Rubyforge and install it like so:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html&quot;&gt;sudo gem install enhanced_migrations-1.2.1.gem&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Update - 11/15/2007&lt;/span&gt;&lt;br /&gt;The previous version had a small bug that was discovered during use here that sometimes caused an app&#39;s database yaml file to be overwritten by the gem&#39;s database config which is used only for testing. The chances of this happening outside of our particular setup are small but we felt it warranted an immediate fix. We&#39;ve also added a &lt;a href=&quot;http://rubyforge.org/frs/download.php/27991/enhanced_migrations-1.2.1.tgz&quot;&gt;gzip&#39;d&lt;/a&gt; source file for the plugin fans out there.&lt;br /&gt;&lt;br /&gt;Links in the post have been updated to reflect the location of this &lt;a href=&quot;http://rubyforge.org/frs/shownotes.php?release_id=16408&quot;&gt;new release&lt;/a&gt;.</description><link>http://revolutiononrails.blogspot.com/2007/11/enhanced-migrations-v120.html</link><author>noreply@blogger.com (Sean)</author><thr:total>13</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-706715425639470563</guid><pubDate>Fri, 24 Aug 2007 21:09:00 +0000</pubDate><atom:updated>2007-08-28T18:10:33.133-07:00</atom:updated><title>Weblog update</title><description>Hey all I wanted to give you an update:&lt;br /&gt;&lt;br /&gt;Three of our active contributors are moving on: Aaron, Eddie, and Val. They plan to stay active in the Rails community, as well as new areas like &lt;a href=&quot;http://www.facebook.com&quot;&gt;Facebook&lt;/a&gt;. You can follow their work at &lt;a href=&quot;http://blog.hungrymachine.com&quot;&gt;blog.hungrymachine.com&lt;/a&gt;. It has been a great pleasure to work with them and we wish them the best.</description><link>http://revolutiononrails.blogspot.com/2007/08/weblog-update.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-1664382480956432677</guid><pubDate>Mon, 06 Aug 2007 21:16:00 +0000</pubDate><atom:updated>2007-08-26T17:42:22.585-07:00</atom:updated><title>FragmentFu - Fun with Fragments</title><description>First, please read the &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/08/advanced-rails-caching-on-edge.html&quot;&gt;Advanced Rails Caching.. On the Edge&lt;/a&gt; for a primer on ESI, caching, and fragments.&lt;br /&gt;To get started developing with ESI, I&#39;m going to walk through a simple tutorial building an ESI enabled Rails application.&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Get Mongrel-ESI&lt;/span&gt;&lt;br /&gt;   Find the latest mongrel ESI here: http://code.google.com/p/mongrel-esi/downloads/list&lt;br /&gt;   &lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;   wget http://mongrel-esi.googlecode.com/files/mongrel-esi-0.0.5.gem&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;(Does anyone have a better solution of ruby projects hosted on Google Code? )&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Install Mongrel ESI&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;     sudo gem install mongrel-esi-0.0.5.gem&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Create a new rails application&lt;/span&gt;  (Currently using rails 1.2.3)&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;   rails fragment_fu_demo&lt;br /&gt;&lt;br /&gt;     create  &lt;br /&gt;     create  app/controllers&lt;br /&gt;     create  app/helpers&lt;br /&gt;     create  app/models&lt;br /&gt;     .....&lt;br /&gt;&lt;br /&gt;   cd fragment_fu_demo&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;br /&gt;Create a home page for your application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  Delete the public/index.html page&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;     rm public/index.html&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  Edit the config/routes.rb and uncomment the following line:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;     map.connect &#39;&#39;, :controller =&gt; &quot;welcome&quot;&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  Create a welcome controller&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;     ./script/generate controller welcome index&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Install the FragmentFu plugin&lt;/span&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;   &lt;br /&gt;  ./script/plugin install http://mongrel-esi.googlecode.com/svn/trunk/plugin/fragment_fu&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Start your application&lt;br /&gt;&lt;/span&gt;  &lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt; &lt;br /&gt;  ./script/server&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  visit http://localhost:3000 in your browser.  You should see a &quot;Welcome#index&quot; page.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Start MongrelEsi &lt;/span&gt;&lt;br /&gt;From the command line, run:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt; mongrel_esi start&lt;br /&gt;    ** Starting Mongrel listening at 0.0.0.0:2000&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;  visit  http://localhost:2000 in your browser. You should see a &quot;Welcome#index&quot; page.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Create a fragment to cache&lt;/span&gt;&lt;br /&gt;  Edit the app/controllers/welcome_controller.rb&lt;br /&gt;  Add an action called now&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt; &lt;br /&gt;     def now&lt;br /&gt;        render :text =&gt; &quot;#{Time.now} is #{Time.now.usec} nano-seconds&quot;&lt;br /&gt;     end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt; &lt;br /&gt;  Edit the app/views/welcome/index.html.erb and replace with the following:&lt;br /&gt;     &lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;     &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Welcome&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;     &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;/welcome/now&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;       &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Page without ESI parsing&lt;/span&gt;&lt;br /&gt;   visit http://localhost:3000 and you should see:  &quot;Time:&quot; in the browser.  If you view the source, you&#39;ll see&lt;br /&gt;    &lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Welcome&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:include&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;/welcome/now&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;max-age&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is the simplest of esi tags, and the default max-age is 0, which means do not cache.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Page with ESI Parsing &lt;br /&gt;&lt;/span&gt;   &lt;br /&gt;visit http://localhost:2000 and you&#39;ll see: &lt;br /&gt;    &lt;br /&gt;    Welcome&lt;br /&gt; Date: Mon Aug 06 00:00:00 -0400 2007 which is 62972ns&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Caching modules&lt;/span&gt;&lt;br /&gt;  Edit the index.html.erb and replace with the following:&lt;br /&gt;   &lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;   &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Welcome&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;/welcome/now&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;What time is it again?&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;/welcome/now&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;   &lt;/span&gt;&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;  If you refresh http://localhost:2000, you&#39;ll notice they nanoseconds are different&lt;br /&gt;  &lt;br /&gt;  Lets add a ttl to first call&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Welcome&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;/welcome/now&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;ttl&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;seconds &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;What time is it again?&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;h2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;/welcome/now&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;  If you refresh http://localhost:2000, you&#39;ll notice they are now the same. Refresh again in the next 45 seconds, and it will not change.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The next tutorial will cover a small TODO application, with inline invalidation and exception handling. Coming Soon!</description><link>http://revolutiononrails.blogspot.com/2007/08/fragmentfu-fun-with-fragments.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-3354941472549880431</guid><pubDate>Mon, 06 Aug 2007 17:15:00 +0000</pubDate><atom:updated>2007-08-06T10:59:14.414-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">caching</category><category domain="http://www.blogger.com/atom/ns#">esi</category><category domain="http://www.blogger.com/atom/ns#">rails</category><title>Advanced Rails Caching.. on the Edge</title><description>When trying to scale a portal to millions of users with complex personalization, we had to rethink the application design. We needed partial page cacheability, and we wanted that close to the Edge... and recently the idea has been catching on.  First with &lt;a href=&quot;http://kylemaxwell.com/2007/6/21/components-are-the-new-black&quot;&gt;Components Are the New Black&lt;/a&gt;, and the idea of &lt;a href=&quot;http://blog.kovyrin.net/2007/08/05/using-nginx-ssi-and-memcache-to-make-your-web-applications-faster&quot;&gt;Nginx, SSI, and Memcache&lt;/a&gt;, what I&#39;d like to briefly describe below is a partial page caching strategy that has worked well for the past year.&lt;br /&gt;&lt;br /&gt;First, we use a technology called ESI.  ESI stands for &lt;a href=&quot;http://www.w3.org/TR/esi-lang&quot;&gt;Edge Side Includes&lt;/a&gt;, which is a simple markup language for describing dynamic assembly of applications.  At the core, its similar to SSI, but its a more versatile spec that has been accepted/implemented by a half dozen cache servers, both open source (&lt;a href=&quot;http://longsleep.org/1/howto/squidwithzopeandesi&quot;&gt;Squid&lt;/a&gt;, &lt;a href=&quot;http://code.google.com/p/mongrel-esi/&quot;&gt;Mongrel-ESI&lt;/a&gt;) and commercial (&lt;a href=&quot;http://www.oracle.com/technology/products/ias/web_cache/&quot;&gt;Oracle Web Cache&lt;/a&gt;, &lt;a href=&quot;http://www.akamai.com/html/support/esi.html&quot;&gt;Akamai&lt;/a&gt;, among others). It also includes an invalidation protocol, exception handling on the edge, and a few other features. &lt;br /&gt;&lt;br /&gt;The &lt;a href=&quot;http://www.w3.org/TR/esi-lang&quot;&gt;ESI W3C specification&lt;/a&gt; has been out for 6+ years, so these ideas are not new, but ESI is a diamond in the rough. No one seems to be using it. &lt;br /&gt;&lt;br /&gt;A simple example of ESI in your rails application is including a common header.  If the header is static, using a shared layout, or rendering a shared partial across applications, could be sufficient.  But if you use the common idiom of a sign-in bar, like &quot;Welcome Bob - Signout&quot;, on a page you want to fully cache, or a common header you want to share across multiple applications, then you may consider another approach.  &lt;br /&gt;&lt;br /&gt;If you leverage ESI, you can put the below in your application layout.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;meta meta_attribute-with-value meta_attribute-with-value_id meta_attribute-with-value_id_html&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_html&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_html&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;meta meta_toc-list meta_toc-list_id meta_toc-list_id_html&quot;&gt;header&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:include&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;/header&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;max-age&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;300&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The &lt;a href=&quot;http://download-west.oracle.com/docs/cd/B14099_02/caching.1012/b14046/esi.htm#i635776&quot;&gt;&amp;lt;esi:include&amp;gt;&lt;/a&gt;  tag will inject the response from /header into the page and cache that fragment for 300 seconds. You can also add a variety of options, request header parameters (which can be used to personalize the request) along with a dozen other optional parameters, some of which I will outline below.  This is simple &lt;a href=&quot;http://en.wikipedia.org/wiki/Server_Side_Includes&quot;&gt;SSI (Server Side Includes) &lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;But if we take it a step further, lets look at how we can apply it to a site like Twitter.&lt;br /&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://4.bp.blogspot.com/_W2nz-v3KRJI/RrdYE9Dn4aI/AAAAAAAAABQ/wk1Sc-QAK2A/s1600-h/twitter-annotated.png&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;&quot; src=&quot;http://4.bp.blogspot.com/_W2nz-v3KRJI/RrdYE9Dn4aI/AAAAAAAAABQ/wk1Sc-QAK2A/s320/twitter-annotated.png&quot; border=&quot;0&quot; alt=&quot;Twitter&quot; id=&quot;BLOGGER_PHOTO_ID_5095638345525485986&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you look at the image above, the majority of the page can be fully cached. I&#39;ve outlined two green boxes, which appear to be dynamic content, which can have different TTLs.  Using ESI, your markup could be: &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;meta meta_attribute-with-value meta_attribute-with-value_id meta_attribute-with-value_id_html&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_html&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_html&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;meta meta_toc-list meta_toc-list_id meta_toc-list_id_html&quot;&gt;latest&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:include&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;/latest&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;max-age&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;5&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;...&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:include&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;/featured&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;max-age&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;3600&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The ESI enabled cache server would parse this markup, make 2 separate HTTP requests (/latest, and /featured) and cache those with their corresponding TTLs. You can furthermore cache the wrapping template with a &lt;a href=&quot;http://www.w3.org/TR/edge-arch&quot;&gt;Surrogate-Control&lt;/a&gt; header, which tells the cache server to keep a cached copy of the template. A request to this page 4 seconds later would make 0 requests to your rails infrastructure. 8 seconds later would only hit the /latest, returning the rest of the page from cache.  You can also envision a application pool of servers just to handle /latest, but I&#39;ll get into sharding applications via ESI in a later article.  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Exception Handling&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you take this a step further, you can also define timeouts and exception behavior.  As defined below, If the /latest request takes more than 1s, The cache server will give up, and retrieve the static snippet defined in the except block from your static web host. &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:try&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:attempt&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:include&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;/latest&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;max-age&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;5&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;timeout&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;1&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:attempt&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:except&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:include&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;src&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;http://static.foo.com/latest&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;max-age&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;5&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;timeout&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;1&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:except&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:try&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We call these &quot;Sorry&quot; modules, because they often say &quot;Sorry, this feature is having trouble&quot;, but the rest of the page may surface meaningful content.  Even better, write out more meaningful content to disk once a day and serve that from Apache. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;br /&gt;Invalidation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The other benefit of ESI is Invalidation support.  There are various mechanisms to invalidate content, but my favorite is &lt;a href=&quot;http://download-west.oracle.com/docs/cd/B14099_02/caching.1012/b14046/invalidate.htm#i1040426&quot;&gt;Inline Invalidation&lt;/a&gt;.  Consider the common rails idiom of updating data. You post to a controller which redirects to a view of that data.  Since the HTTP redirect (301) bubbles all the way back to the browser, any content in the body of the redirect can be parsed by the ESI server.  Therefore you can put the invalidation xml is the redirect response body and not conditionally dirty your view logic.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:invalidate&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_preprocessor meta_tag_preprocessor_xml meta_tag_preprocessor_xml_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;?&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_xml entity_name_tag_xml_html&quot;&gt;xml&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;version&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;1.0&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_sgml meta_tag_sgml_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_sgml meta_tag_sgml_doctype meta_tag_sgml_doctype_html&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_doctype entity_name_tag_doctype_html&quot;&gt;DOCTYPE&lt;/span&gt; INVALIDATION SYSTEM &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_doctype string_quoted_double_doctype_identifiers-and-DTDs string_quoted_double_doctype_identifiers-and-DTDs_html&quot;&gt;&quot;internal:///WCSinvalidation.dtd&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;INVALIDATION&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;VERSION&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;WCS-1.1&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;BASICSELECTOR&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;URI&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;/foo/bar/baz&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;ACTION&lt;/span&gt; &lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_html&quot;&gt;REMOVALTTL&lt;/span&gt;=&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;0&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;OBJECT&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;INVALIDATION&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_other meta_tag_other_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_other entity_name_tag_other_html&quot;&gt;esi:invalidate&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above is a simple single URL example, but the specification supports regex, which would work well for restful resources (e.g. /people/#{person.id}/*), among other things.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;br /&gt;FragmentFu&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;FragmentFu is a plugin that enables ESI support in rails applications.  At this point it is an extraction from our internal plugin for modules, caching, and ESI.  Its in active extraction/development, but I wanted to involve the community in gathering ideas, suggestions and comments.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Some sample snippets:&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; widget_url&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack gatheringsupport_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; latest_url&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;ttl&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;seconds&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;timeout&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;second &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;esi&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; featured_url&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;ttl&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;hours&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;except&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/some/static/path&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We&#39;ve also toyed around with the idea of fragment respond_to&#39;s. Since ESI supports adding request header parameters, we can mimic Prototype&#39;s&lt;br /&gt;X-Requested-With behavior to implement: &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;latest&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;...&lt;/span&gt;&lt;br /&gt;  respond_to &lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;|&lt;/span&gt;wants&lt;span class=&quot;keyword keyword_operator keyword_operator_other keyword_operator_other_ruby&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do&lt;br /&gt;&lt;/span&gt;    wants&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;html &lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;something &lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;}&lt;/span&gt;&lt;br /&gt;    wants&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;fragment &lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;something &lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;}&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;br /&gt;How to get started&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Mongrel-ESI is a great starting place. It was built in-house and released a few months ago on Google Code.  It supports a large subset of ESI, ESI Invalidation, and its a great tool for developing applications that utilize ESI. You can grab &lt;a href=&quot;http://code.google.com/p/mongrel-esi/&quot;&gt;Mongrel-ESI&lt;/a&gt;, download the &lt;a gatheringhref=&quot;http://www.oracle.com/technology/products/ias/web_cache/index.html&quot;&gt;Oracle Web Cache Standalone&lt;/a&gt; or even &lt;a href=&quot;http://longsleep.org/1/howto/squidwithzopeandesi&quot;&gt;Squid 3.0&lt;/a&gt;... and when you&#39;re site gets really big, its time to give Akamai a call. :)</description><link>http://revolutiononrails.blogspot.com/2007/08/advanced-rails-caching-on-edge.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/_W2nz-v3KRJI/RrdYE9Dn4aI/AAAAAAAAABQ/wk1Sc-QAK2A/s72-c/twitter-annotated.png" height="72" width="72"/><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-289099066403644087</guid><pubDate>Sun, 24 Jun 2007 13:06:00 +0000</pubDate><atom:updated>2007-06-24T11:18:54.859-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ajax</category><category domain="http://www.blogger.com/atom/ns#">code digest</category><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">ruby</category><title>Code Digest #2</title><description>When you program for a living, you write lots of code. There is often some code that you are fond of. We started the Code Digest series to present such code written by the RHG developers. We encourage other teams and individual developers to share similar snippets in their blogs so we all can learn from each other and become better rails developers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://workingwithrails.com/person/8775-mai-nguyen&quot;&gt;Mai Nguyen&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;i&gt;Simple AJAX error messaging&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;When simple javascript validation is not enough and your product managers insist on ajax for error messaging, guess what. You have to implement ajax error messaging. One such case is &#39;username availability&#39;. This simple example displays an error message on blur of a the username field. It doesn&#39;t hit the server unless the value of the field is well-formed (at least that will save you *some* network traffic ...)&lt;br /&gt;&lt;br /&gt;Controller would look something like:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_rails meta_rails_controller&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;FooController&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ::ApplicationController&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;is_username_taken&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Person&lt;/span&gt;.find_by_username(params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;username&lt;/span&gt;])&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;nothing&lt;/span&gt; =&amp;gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;return&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    message_html_id = params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;message_html_id&lt;/span&gt;]&lt;br /&gt;    &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;update&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|page|&lt;br /&gt;      page.replace_html message_html_id ,&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Username is not available, please choose another.&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;      &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; if you want error styling associated with the failed state&lt;br /&gt;&lt;/span&gt;      page &amp;lt;&amp;lt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;document.getElementById(&#39;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; + message_html_id + &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&#39;).className = &#39;failed&#39;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;View would look something like:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dl&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Username: &lt;span class=&quot;meta meta_tag meta_tag_inline meta_tag_inline_any meta_tag_inline_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_inline entity_name_tag_inline_any entity_name_tag_inline_any_html&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dd&lt;/span&gt; &lt;span class=&quot;meta meta_attribute-with-value meta_attribute-with-value_id meta_attribute-with-value_id_html&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_html&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_html&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;meta meta_toc-list meta_toc-list_id meta_toc-list_id_html&quot;&gt;username_input&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; text_field &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;person&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;username&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;class&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;input&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;type&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;text&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;id&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;person_username_input&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dd&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dd&lt;/span&gt; &lt;span class=&quot;meta meta_attribute-with-value meta_attribute-with-value_id meta_attribute-with-value_id_html&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_attribute-name entity_other_attribute-name_id entity_other_attribute-name_id_html&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_html&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_html&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;meta meta_toc-list meta_toc-list_id meta_toc-list_id_html&quot;&gt;username_messaging&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_html&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;person&lt;/span&gt;.errors.on(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;username&lt;/span&gt;)&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dd&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_tag meta_tag_block meta_tag_block_any meta_tag_block_any_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_block entity_name_tag_block_any entity_name_tag_block_any_html&quot;&gt;dl&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_tag punctuation_definition_tag_html&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Your javascript would look something like:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_js&quot;&gt;&lt;span class=&quot;storage storage_type storage_type_js&quot;&gt;var&lt;/span&gt; UserNameUnique &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;=&lt;/span&gt; Class&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;create&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_js&quot;&gt;&lt;span class=&quot;support support_class support_class_js&quot;&gt;UserNameUnique&lt;/span&gt;.&lt;span class=&quot;support support_constant support_constant_js&quot;&gt;prototype&lt;/span&gt; = &lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_json meta_function_json_js&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_function entity_name_function_js&quot;&gt;initialize&lt;/span&gt;: &lt;span class=&quot;storage storage_type storage_type_function storage_type_function_js&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_begin punctuation_definition_parameters_begin_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_js&quot;&gt; field_id, message_id&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_end punctuation_definition_parameters_end_js&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;{&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;message_id &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;=&lt;/span&gt; message_id&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;field &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;support support_class support_class_js&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;support support_function support_function_dom support_function_dom_js&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt; field_id &lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_js&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;field &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;undefined&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_js&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;}&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;comment comment_line comment_line_double-slash comment_line_double-slash_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_js&quot;&gt;//&lt;/span&gt; Observe blur on field    &lt;br /&gt;&lt;/span&gt;        Event&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;observe&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;field&lt;span class=&quot;meta meta_delimiter meta_delimiter_object meta_delimiter_object_comma meta_delimiter_object_comma_js&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;blur&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_object meta_delimiter_object_comma meta_delimiter_object_comma_js&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;checkName&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;bindAsEventListener&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_object meta_delimiter_object_comma meta_delimiter_object_comma_js&quot;&gt;,&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_json meta_function_json_js&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_function entity_name_function_js&quot;&gt;checkName&lt;/span&gt;: &lt;span class=&quot;storage storage_type storage_type_function storage_type_function_js&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_begin punctuation_definition_parameters_begin_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_end punctuation_definition_parameters_end_js&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_js&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;field &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;undefined&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;)&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;{&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;storage storage_type storage_type_js&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;field&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;support support_constant support_constant_dom support_constant_dom_js&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;comment comment_line comment_line_double-slash comment_line_double-slash_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_js&quot;&gt;//&lt;/span&gt; don&#39;t hit server unless username is well-formed&lt;br /&gt;&lt;/span&gt;            &lt;span class=&quot;storage storage_type storage_type_js&quot;&gt;var&lt;/span&gt; re &lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_js&quot;&gt; &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;/&lt;/span&gt;^[A-Za-z])[a-zA-Z0-9]{2,25}$&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;keyword keyword_control keyword_control_js&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt; name&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;support support_function support_function_js&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt; re &lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;))&lt;/span&gt;&lt;br /&gt;                &lt;span class=&quot;meta meta_class meta_class_instance meta_class_instance_constructor&quot;&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_new keyword_operator_new_js&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_instance entity_name_type_instance_js&quot;&gt;Ajax.Request&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;/foo/is_username_taken&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_object meta_delimiter_object_comma meta_delimiter_object_comma_js&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;{&lt;/span&gt;asynchronous:&lt;span class=&quot;constant constant_language constant_language_boolean constant_language_boolean_true constant_language_boolean_true_js&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_object meta_delimiter_object_comma meta_delimiter_object_comma_js&quot;&gt;, &lt;/span&gt;parameters:&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;username=&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;+&lt;/span&gt;name&lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;&amp;amp;message_html_id=&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_js&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;variable variable_language variable_language_js&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_method meta_delimiter_method_period meta_delimiter_method_period_js&quot;&gt;.&lt;/span&gt;message_id&lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_brace meta_brace_curly meta_brace_curly_js&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_instance meta_class_instance_constructor&quot;&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_new keyword_operator_new_js&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_instance entity_name_type_instance_js&quot;&gt;UserNameUnique&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;person_username_input&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_delimiter meta_delimiter_object meta_delimiter_object_comma meta_delimiter_object_comma_js&quot;&gt;, &lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_js&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_js&quot;&gt;&#39;&lt;/span&gt;username_messaging&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_js&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_brace meta_brace_round meta_brace_round_js&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_terminator punctuation_terminator_statement punctuation_terminator_statement_js&quot;&gt;;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You could also use Rails helper observe_field instead of the writing your own javascript, but there is more flexibility in writing your own javascript (such as the need to check well-formed values before hitting the server).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://workingwithrails.com/person/8412-mark-brooks&quot;&gt;Mark Brooks&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;Creating the options list for select tags can be annoying, especially if there is a requirement that the current &quot;option&quot; be displayed as the default option. With javascript, it isn&#39;t such a big deal, but one must take care of the degraded case as well.&lt;br /&gt;&lt;br /&gt;In any event, the base object is an array of two-item hashes representing both the name of a video channel and the number of videos in that channel. By way of example:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;channelinfo&lt;/span&gt; = [&lt;br /&gt;  {&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Fitness&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;,&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;count&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;4&lt;/span&gt;},&lt;br /&gt;  {&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Diabetes&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;count&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;1&lt;/span&gt;},&lt;br /&gt;  {&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Pregnancy&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;count&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;11&lt;/span&gt;}&lt;br /&gt;]&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The option values are the &lt;i&gt;name&lt;/i&gt; fields of each hash. The key is, we want the &lt;i&gt;current&lt;/i&gt; option value to be the first one in the option list, and the rest to be in alpha order by &lt;i&gt;name&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;So let&#39;s create an option builder from the bottom up. &lt;br /&gt;&lt;br /&gt;First, we only need the channel names for the select tag.  This gives us what we need:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;options = &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;channelinfo&lt;/span&gt;.collect {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|channel| channel[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;] }&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That gives us a list of channel names. Using the list above, it would be &lt;i&gt;[&quot;Fitness&quot;, &quot;Diabetes&quot;, &quot;Pregnancy&quot;]&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;However, we need to make sure that the &lt;b&gt;current&lt;/b&gt; channel is first in the list. Let&#39;s say that current channel is &lt;i&gt;Diabetes&lt;/i&gt;. Since we already have that value in @current_channel, we can exclude it from our options list:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;options = &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;channelinfo&lt;/span&gt;.collect &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channel|&lt;br /&gt;  channel[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.reject &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channelname|&lt;br /&gt;  channelname == &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now the resulting list will look like &lt;i&gt;[&quot;Fitness&quot;, &quot;Pregnancy&quot;]&lt;/i&gt;. However, we still need the current channel to be at the front of the lift, so we add it back as the first element:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;options = &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;channelinfo&lt;/span&gt;.collect &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channel|&lt;br /&gt;  channel[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.reject &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channelname|&lt;br /&gt;  channelname == &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.unshift(&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now our options list looks like &lt;i&gt;[&quot;Diabetes&quot;, &quot;Fitness&quot;, &quot;Pregnancy&quot;]&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Two points. First, we want to make sure that, while the current channel is at the head of the list, the rest of the list items are in alpha order, so we add a sort directive in the appropriate place.  Also, it is probably a good idea to exclude any nils that might pop up in the collection on the original data object, since it comes from a service and it is possible, however unlikely, that a hash might get spit out without a &#39;name&#39; property. The more rigorous code looks like this now:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;options = &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;channelinfo&lt;/span&gt;.collect &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channel|&lt;br /&gt;  channel[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.compact.reject &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;| channelname |&lt;br /&gt;  channelname == &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.sort.unshift(&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we can generate our options list using:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;options.collect &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channelname|&lt;br /&gt;  &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&amp;lt;option&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; + channelname + &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&amp;lt;/option&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.join(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;,&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;although if you want to, you can simply combine the whole thing as follows:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;channelinfo&lt;/span&gt;.collect &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channel|&lt;br /&gt;  channel[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.compact.reject &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channelname|&lt;br /&gt;  channelname == &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.sort.unshift(&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;current_channel&lt;/span&gt;).collect &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|channelname|&lt;br /&gt;  &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&amp;lt;option&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; + channelname + &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&amp;lt;/option&amp;gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;.join(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;,&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;)&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;to get the same result, and eliminate the unnecessary &lt;i&gt;options&lt;/i&gt; binding.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://www.workingwithrails.com/person/8498-todd-fisher&quot;&gt;Todd Fisher&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;Here is an extension trying to execute a block multiple times before giving up. Handy for network operations and such.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;Kernel&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;could_fail&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;retries = &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;3&lt;/span&gt;, &amp;amp;block&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    tries = &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;0&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;yield&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Exception&lt;/span&gt;&lt;br /&gt;      tries += &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;1&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; tries &amp;lt; retries&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;retry&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;raise&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Call it as &lt;i&gt;result = could_fail {  some_operation_that_might_fail_first_time }&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://www.workingwithrails.com/person/8498-todd-fisher&quot;&gt;Todd Fisher&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;When you are writing a script that needs to auto install gems, you are likely to run into a problem that it stops because there are multiple platform versions available (jruby, win32, etc) and the gem command expects you to pick one that matches your platform. This patch forces to use a specific platform so no user interaction is needed. &lt;a href=&quot;http://svn.bountysource.com/fishplate/scripts/debian_install.pl&quot;&gt;Original idea from Warren&lt;/a&gt; updated to support rubygems 0.9.4.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;GemTasks&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;setup&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_global variable_other_readwrite_global_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;$&lt;/span&gt;gems_initialized&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_global variable_other_readwrite_global_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;$&lt;/span&gt;gems_initialized&lt;/span&gt; = &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Gem&lt;/span&gt;.manage_gems&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;    &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; see =&amp;gt; http://svn.bountysource.com/fishplate/scripts/debian_install.pl&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Gem&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;RemoteInstaller&lt;/span&gt;.class_eval &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do&lt;br /&gt;&lt;/span&gt;      &lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;alias_method&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;find_gem_to_install_without_ruby_only_platform&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;find_gem_to_install&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;      &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;find_gem_to_install&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt; gem_name, version_requirement, caches = &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;nil&lt;/span&gt; &lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; caches &lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; old version of rubygems used to pass a caches object&lt;br /&gt;&lt;/span&gt;          caches.each {|k,v| caches[k].each {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|name,spect| caches[k].remove_spec(name) &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; spec.platform == &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;ruby&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; } }&lt;br /&gt;          find_gem_to_install_without_ruby_only_platform( gem_name, version_requirement, caches )&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;          &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Gem&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;StreamUI&lt;/span&gt;.class_eval &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do&lt;br /&gt;&lt;/span&gt;            &lt;br /&gt;            &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;alias_method&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;choose_from_list_without_choosing_ruby_only&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;choose_from_list&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;choose_from_list&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt; question, list &lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;              result = &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;nil&lt;/span&gt;&lt;br /&gt;              result_index = -&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;1&lt;/span&gt;&lt;br /&gt;              list.each_with_index &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do  &lt;/span&gt;|item,index|&lt;br /&gt;                &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; item.match(&lt;span class=&quot;string string_regexp string_regexp_classic string_regexp_classic_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;constant constant_character constant_character_escape constant_character_escape_ruby&quot;&gt;\(&lt;/span&gt;ruby&lt;span class=&quot;constant constant_character constant_character_escape constant_character_escape_ruby&quot;&gt;\)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;/span&gt;)&lt;br /&gt;                  result_index = index&lt;br /&gt;                  result = item&lt;br /&gt;                  &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;break&lt;/span&gt;&lt;br /&gt;                &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;              &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;              &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;return&lt;/span&gt; [result, result_index]&lt;br /&gt;            &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;            &lt;br /&gt;          &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;          &lt;br /&gt;          find_gem_to_install_without_ruby_only_platform( gem_name, version_requirement )&lt;br /&gt;        &lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://workingwithrails.com/person/8391-val-aleksenko&quot;&gt;Val Aleksenko&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;Since class-level instance variable are not inherited by subclasses, you need to go some extra steps when writing a plugin using them. Depending on the amount of such variables, I have been either defining a method instead of class-level instance variables or forwarding them to subclasses.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example #1.&lt;/i&gt; &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/04/plugin-release-actsasreadonlyable.html&quot;&gt;acts_as_readonlyable&lt;/a&gt; needs to provide a single class level instance variable. Defining a method instead. &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;acts_as_readonlyable&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;*readonly_dbs&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  define_readonly_model_method(readonly_models)&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;define_readonly_model_method&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;readonly_models&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  (&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;class&lt;/span&gt; &amp;lt;&amp;lt; &lt;span class=&quot;variable variable_language variable_language_ruby&quot;&gt;self&lt;/span&gt;; &lt;span class=&quot;variable variable_language variable_language_ruby&quot;&gt;self&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;).class_eval &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do&lt;br /&gt;&lt;/span&gt;    define_method(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;readonly_model&lt;/span&gt;) {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;readonly_models[rand(readonly_models.size)] }&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example #2.&lt;/i&gt; &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/04/plugin-release-actsassecure.html&quot;&gt;acts_as_secure&lt;/a&gt; uses a bunch of variables. Forwarding them to subclasses.&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;acts_as_secure&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;options = {}&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;secure_except&lt;/span&gt; = unsecure_columns(options.delete(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;except&lt;/span&gt;))&lt;br /&gt;  &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;secure_storage_type&lt;/span&gt; = options.delete(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;storage_type&lt;/span&gt;) || &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;binary&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;secure_class_crypto_provider&lt;/span&gt; = options.delete(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;crypto_provider&lt;/span&gt;)&lt;br /&gt;  &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;secure_crypto_providers&lt;/span&gt; = {}&lt;br /&gt;  &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ActsAsSecureClassMethods&lt;/span&gt;)&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ActsAsSecureClassMethods&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;inherited&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;sub&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    [&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;secure_except&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;secure_storage_type&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;secure_class_crypto_provider&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;secure_crypto_providers&lt;/span&gt;].each &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|p|&lt;br /&gt;      sub.instance_variable_set(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;@&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;p &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, instance_variable_get(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;@&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;p &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;))&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;super&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;</description><link>http://revolutiononrails.blogspot.com/2007/06/code-digest-2.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-8265249012614121024</guid><pubDate>Fri, 22 Jun 2007 17:57:00 +0000</pubDate><atom:updated>2007-06-22T08:56:00.781-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">metics</category><category domain="http://www.blogger.com/atom/ns#">performance</category><category domain="http://www.blogger.com/atom/ns#">rails</category><title>[PLUGIN RELEASE] Metrics</title><description>&lt;p&gt;&lt;br /&gt;From &lt;a href=&quot;http://workingwithrails.com/person/8497-jeffrey-damick&quot;&gt;&lt;b&gt;Jeffrey Damick&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This gem provides a metrics collecting for controllers, database queries, and specific blocks of code or methods.  It is designed to be light-weight and have minimal impact on production builds while providing performance indicators of the running application.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Disclaimer&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This software is released to be used at your own risk. For feedback please drop us a line at rails-trunk [ at ] revolution DOT com.&lt;br /&gt;Using this plugin should not be your first step in application optimization/scaling or even the second one.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Example&lt;/b&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;SomeClassToTest&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  collect_metrics_on &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;my_method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;my_method&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;blah = &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;nil&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Output:&lt;/i&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;[&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ERROR&lt;/span&gt;] [&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;2007&lt;/span&gt;-&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;06&lt;/span&gt;-&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;21&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;23&lt;/span&gt;:&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;21&lt;/span&gt;:&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;19&lt;/span&gt;] [trunk] [&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Metrics&lt;/span&gt;]|[&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;76716&lt;/span&gt;]|[&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;MysqlAdapter&lt;/span&gt;.log]|&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;0.012727&lt;/span&gt;|args=[&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;root localhost trunk_test&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;CREATE DATABASE `trunk_test`&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;[&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ERROR&lt;/span&gt;] [&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;2007&lt;/span&gt;-&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;06&lt;/span&gt;-&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;21&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;23&lt;/span&gt;:&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;19&lt;/span&gt;:&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;56&lt;/span&gt;] [trunk] [&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Metrics&lt;/span&gt;]|[&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;35158&lt;/span&gt;]|[&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Request&lt;/span&gt; to [&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Test&lt;/span&gt;::&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;SomeControllerWithMetricsId&lt;/span&gt;]]|&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;0.001373&lt;/span&gt;|action = index|path =some?&lt;br /&gt;[&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ERROR&lt;/span&gt;] [&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;2007&lt;/span&gt;-&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;06&lt;/span&gt;-&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;21&lt;/span&gt; &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;23&lt;/span&gt;:&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;19&lt;/span&gt;:&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;56&lt;/span&gt;] [trunk] [&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Metrics&lt;/span&gt;]|[&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;33676&lt;/span&gt;]|[&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;SomeClassToUseModuleMixin&lt;/span&gt;.another_method]|&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;0.000020&lt;/span&gt;|args=[&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;also&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;]&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;for more samples and test cases see &lt;i&gt;test/metrics_test.rb&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Usage&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The metrics are written to:  logs/&lt;environment&gt;_metrics.log&lt;br /&gt;&lt;br /&gt;Configuration can be updated in &lt;i&gt;metrics/config/metrics.yml&lt;/i&gt;, you may copy this file to your RAILS_ROOT/config/metrics.yml and customize for your application, the &lt;i&gt;RAILS_ROOT&lt;/i&gt; will be checked first.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Sample metrics.yml&lt;/b&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_yaml&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;production&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;  &lt;span class=&quot;constant constant_numeric constant_numeric_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;min_real_time_threshold&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; 1.0&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;single_line_output&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;some_module/test_controller&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt; &lt;/span&gt;0.0&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Installation&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;As plugin:&lt;br /&gt;&lt;i&gt;script/plugin install svn://rubyforge.org/var/svn/metrics/trunk/vendor/plugins/metrics&lt;/i&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;License&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;metrics is released under the MIT license.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Support&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The plugin RubyForge page is &lt;a href=&quot;http://rubyforge.org/projects/metrics&quot;&gt;http://rubyforge.org/projects/metrics&lt;/a&gt;</description><link>http://revolutiononrails.blogspot.com/2007/06/plugin-release-metrics.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-1094097757866666439</guid><pubDate>Sun, 17 Jun 2007 14:45:00 +0000</pubDate><atom:updated>2007-06-18T13:27:39.799-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">digest</category><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">rhg</category><category domain="http://www.blogger.com/atom/ns#">ruby</category><title>Code Digest #1</title><description>When you program for a living, you write lots of code. There is often some code that you are fond of. We start the Code Digest series to present such code written by the RHG developers. We encourage other teams and individual developers to share similar snippets in their blogs so we all can learn from each other and become better rails developers.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Daniel Silva&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; link_to(image_tag(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;/images/icon.gif&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;style&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;padding-right:0px;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;), {&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;controller&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/registration&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;action&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;login&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;dest&lt;/span&gt; =&amp;gt; request.request_uri}, {&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;style&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;}) &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;With this line, I can create an image link using Rails code, to take advantage of the power of routes in Rails while still creating this kind of structure: &lt;i&gt;&amp;lt;a href=&quot;#&quot;&amp;gt;&amp;lt;img border=&quot;0&quot;/&amp;gt;&amp;lt;/a&amp;gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://workingwithrails.com/person/8396-jack-dempsey&quot;&gt;Jack Dempsey&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;Ok, so here&#39;s something useful for using keyboard short cuts to navigate through a small supporting application:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;include_keyboard_shortcuts&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  hotkey = &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;Ctrl+Shift&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  code_string = &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  keys = {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt;&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;m&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/account_info/show&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;s&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/account_info/index&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;c&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/menu/go?menu_action=new_customer&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;p&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/products&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;o&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/account_info/orders&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;t&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/order_tracker&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;x&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/auth_sessions/destroy&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;,&lt;br /&gt;    &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;r&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;=&amp;gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/current_users/reset_password&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  current_user_needed = &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_literal string_quoted_other_literal_lower string_quoted_other_literal_lower_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;%w{&lt;/span&gt;m o r&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  keys.each_pair &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|k,v|&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;next&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; current_user_needed.include?(k) &amp;amp;&amp;amp; current_user.nil?&lt;br /&gt;    code_string &amp;lt;&amp;lt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;shortcut(&#39;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;hotkey&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;+hm&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;k&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&#39;,function() { document.location.href=&#39;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;v&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&#39; });&lt;span class=&quot;constant constant_character constant_character_escape constant_character_escape_ruby&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  javascript_tag(code_string)&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then in a layout file just:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_html text_html_ruby&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; javascript_include_tag &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;shortcuts&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;source source_ruby source_ruby_rails source_ruby_rails_embedded source_ruby_rails_embedded_html&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;&amp;lt;%=&lt;/span&gt; include_keyboard_shortcuts &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Makes use of &lt;a href=&quot;http://www.openjs.com/scripts/events/keyboard_shortcuts/&quot;&gt;a nice shortcuts.js lib.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://workingwithrails.com/person/8391-val-aleksenko&quot;&gt;Val Aleksenko&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;This is a fragment of a conversation on our internal IRC with my solution for refactoring a piece of code:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_plain&quot;&gt;&lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;&lt;span class=&quot;support&quot;&gt;May 07 14:07:56&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;&amp;lt;Anthro&amp;gt;&lt;/span&gt; There has to be a better way to do this (x and y are non-negative integers): increment = (x!=0) ? ( (y!=0) ? 0 : 1 ) : -1&lt;br /&gt;&lt;span class=&quot;support&quot;&gt;May 07 14:08:22&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;&amp;lt;Anthro&amp;gt;&lt;/span&gt; I think it can be done with math instead of logic.&lt;br /&gt;&lt;span class=&quot;support&quot;&gt;May 07 14:16:56&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;&amp;lt;jack&amp;gt;&lt;/span&gt;  Anthro: have you thought about using sin and cos? ;-)&lt;br /&gt;&lt;span class=&quot;support&quot;&gt;May 07 14:18:42&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;&amp;lt;muzzy&amp;gt;&lt;/span&gt; (x &amp;lt;=&amp;gt; 0) &amp;lt;=&amp;gt; (y &amp;lt;=&amp;gt; 0)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Granted, it is not as clear as the original, but it is hard to resist it from the aesthetic point of view. &lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://workingwithrails.com/person/8391-val-aleksenko&quot;&gt;Val Aleksenko&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;I love writing dynamically generated methods and classes in Ruby as the next guy. When I was writing &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/04/plugin-release-actsasreadonlyable.html&quot;&gt;acts_as_readonlyable&lt;/a&gt;, I needed to manage multiple connections. I found that the easiest solution for managing active connections was generation of an AR class for each read-only definition and borrowing the connection from it. The usage is &lt;i&gt;acts_as_readonlyable :read_only_entry_in_database_config&lt;/i&gt;.&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;acts_as_readonlyable&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;readonly_db&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  define_readonly_class(readonly_db) &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;.const_defined?(readonly_class_name(readonly_db))&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;readonly_class_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Generated&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;db.camelize &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;define_readonly_class&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;.module_eval &lt;span class=&quot;string string_quoted string_quoted_other string_quoted_other_literal string_quoted_other_literal_upper string_quoted_other_literal_upper_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;%Q!&lt;/span&gt;&lt;br /&gt;    class &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;readonly_class_name(db) &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &amp;lt; Base&lt;br /&gt;      self.abstract_class = true&lt;br /&gt;      establish_connection configurations[RAILS_ENV][&#39;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;db &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&#39;]&lt;br /&gt;    end&lt;br /&gt;  &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;!&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;&lt;a href=&quot;http://warrenkonkel.com/&quot;&gt;Warren Konkel&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;The ConfigFile class is a quick and easy way to load YAML files located in your Rails application&#39;s config directory.  Simply place a YAML file into your config directory and then access it like a hash.  For example this will read your &lt;i&gt;config/database.yml: ConfigFile[&#39;database&#39;][&#39;production&#39;][&#39;adapter&#39;]&lt;/i&gt;.&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;ConfigFile&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.[]&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_configs&lt;/span&gt; ||= {}&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_config_mtimes&lt;/span&gt; ||= {}&lt;br /&gt;&lt;br /&gt;    base_name = &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;config/&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;arg&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;.yml&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    filename = &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.join(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;RAILS_ROOT&lt;/span&gt;, base_name)&lt;br /&gt;    &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;ERROR: Config not found: &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;base_name&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.exists?(base_name)&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_configs&lt;/span&gt;[arg].nil? || &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_config_mtimes&lt;/span&gt;[arg] &amp;lt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.stat(filename).mtime.to_i&lt;br /&gt;      &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_configs&lt;/span&gt;[arg] = &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;YAML&lt;/span&gt;.load(&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.open(filename))&lt;br /&gt;      &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_config_mtimes&lt;/span&gt;[arg] = &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.stat(filename).mtime.to_i&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;cached_configs&lt;/span&gt;[arg]&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;</description><link>http://revolutiononrails.blogspot.com/2007/06/code-digest-1.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-3640618928525420402</guid><pubDate>Thu, 07 Jun 2007 14:16:00 +0000</pubDate><atom:updated>2007-06-07T07:19:05.348-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">blog</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">recipes</category><title>Our Contribution to Advanced Rails Recipes</title><description>We submitted a few recipes, &lt;a href=&quot;http://www.chadfowler.com/2007/5/2/contribute-to-advanced-rails-recipes&quot;&gt;answering the call for sharing what is happing in the rails community&lt;/a&gt;, and a half a dozen of them were accepted as entries to &lt;a href=&quot;http://pragmaticprogrammer.com/titles/fr_arr/index.html&quot;&gt;the upcoming book&lt;/a&gt;. If you enjoyed reading the blog, you would soon have a chance to see some of it on paper.</description><link>http://revolutiononrails.blogspot.com/2007/06/our-contribution-to-advanced-rails.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-7613397780300733877</guid><pubDate>Mon, 04 Jun 2007 14:08:00 +0000</pubDate><atom:updated>2007-06-04T07:35:10.075-07:00</atom:updated><title>Revolution Health Traffic Doubles in 4 Weeks</title><description>&lt;a href=&quot;http://weblogs.hitwise.com/leeann-prescott/2007/05/revolution_health_traffic_doub_1.html&quot;&gt;Hitwise&lt;/a&gt; has recently publish traffic statistics on our growth over the past month.&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt; This Wednesday AOL Founder Steve Case &lt;a href=&quot;http://d5.allthingsd.com/20070530/d5-steve-case/&quot;&gt;spoke&lt;/a&gt; at D5 about his new venture, &lt;a href=&quot;http://www.revolutionhealth.com&quot;&gt;Revolution Health&lt;/a&gt;. Revolution Health is setting out to be far more than just a health information source on the web, but it is already succeeding on that front. For the week ending May 26, 2007, Revolution Health was ranked #11 in the Health &amp; Medical - Information category, and traffic increased by 113% since the week ending April 28, 2007, when it was ranked #23.&lt;/blockquote&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://weblogs.hitwise.com/leeann-prescott/2007/05/revolution_health_traffic_doub_1.html&quot;&gt;&lt;img style=&quot;display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px;&quot; src=&quot;http://weblogs.hitwise.com/leeann-prescott/053107-1.png&quot; border=&quot;0&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;</description><link>http://revolutiononrails.blogspot.com/2007/06/revolution-health-traffic-doubles-in-4.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-8127817989514523196</guid><pubDate>Mon, 04 Jun 2007 03:42:00 +0000</pubDate><atom:updated>2007-06-03T21:34:29.282-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jruby</category><category domain="http://www.blogger.com/atom/ns#">openssl</category><category domain="http://www.blogger.com/atom/ns#">ruby</category><title>Ruby vs. JRuby - The path to consistent behavior + OpenSSL</title><description>In &lt;a href=&quot;http://ola-bini.blogspot.com/&quot;&gt;Ola Bini&lt;/a&gt;&#39;s recent post &lt;a href=&quot;http://ola-bini.blogspot.com/2007/06/there-can-be-only-one-tale-about-ruby.html&quot;&gt;There can be only one, a tale about Ruby, IronRuby, MS and whatnot&lt;/a&gt;, he stresses the importance of documenting Ruby&#39;s API so that other implementations can match MRI&#39;s behavior. I have to strongly agree. We&#39;ve recently been bitten by this, which I&#39;ll outline using OpenSSL as an example.&lt;br /&gt;&lt;br /&gt;Ruby&#39;s OpenSSL library does not strictly enforce a ciphers&#39;s initialization vector (IV) size specification. It simply truncates to the appropriate size. &lt;br /&gt;&lt;br /&gt;Ola&#39;s &lt;a href=&quot;http://rubyforge.org/projects/jruby-extras&quot;&gt;JRuby OpenSSL&lt;/a&gt; library (which is awesome btw!) leverages the &lt;a href=&quot;http://www.bouncycastle.org/&quot;&gt;Bouncy Castle&#39;s&lt;/a&gt; JCE implementation which strictly enforces IV specifications.&lt;br /&gt;&lt;br /&gt;Below is a simple example that works fine on MRI, and fails on JRuby.&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_require meta_require_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;openssl&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;text &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;abc123&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;cipher &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;OpenSSL&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Cipher&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Cipher&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;des-ecb&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;The DES Cipher specifies a length of 8 bytes, the below IV exceeds that&lt;br /&gt;&lt;/span&gt;key&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; iv &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;1234567890&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;1234567890&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;encrypt&lt;br /&gt;cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;key&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;iv  &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt;  key&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; iv&lt;br /&gt;encrypted &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;update&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;text&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;final&lt;br /&gt;&lt;br /&gt;cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;reset&lt;br /&gt;cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;decrypt&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;I double the length of the cipher here, just to prove that MRI truncates it.&lt;br /&gt;&lt;/span&gt;cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;key&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;iv  &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; key&lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; iv&lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;2&lt;/span&gt;&lt;br /&gt;decrypted &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;update&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;encrypted&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; cipher&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;final&lt;br /&gt;puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;text&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt; == &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;decrypted&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_java&quot;&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_java&quot;&gt;&amp;gt;&lt;/span&gt; jruby test_openssl_iv.rb &lt;br /&gt;&lt;span class=&quot;support support_type support_type_java&quot;&gt;java.security.InvalidKeyException&lt;/span&gt;: &lt;span class=&quot;constant constant_other constant_other_java&quot;&gt;DES&lt;/span&gt; key too &lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_java&quot;&gt;-&lt;/span&gt; should be &lt;span class=&quot;constant constant_numeric constant_numeric_java&quot;&gt;8&lt;/span&gt; bytes&lt;br /&gt;        at &lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;org.bouncycastle.jce.provider.JCEBlockCipher&lt;/span&gt;.engineInit(&lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;Unknown&lt;/span&gt; &lt;span class=&quot;support support_type support_type_built-ins support_type_built-ins_java&quot;&gt;Source&lt;/span&gt;)&lt;br /&gt;        at &lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;org.bouncycastle.jce.provider.JCEBlockCipher&lt;/span&gt;.engineInit(&lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;Unknown&lt;/span&gt; &lt;span class=&quot;support support_type support_type_built-ins support_type_built-ins_java&quot;&gt;Source&lt;/span&gt;)&lt;br /&gt;        at &lt;span class=&quot;support support_type support_type_java&quot;&gt;javax.crypto.Cipher&lt;/span&gt;.init(&lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;DashoA12275&lt;/span&gt;)&lt;br /&gt;        at &lt;span class=&quot;support support_type support_type_java&quot;&gt;javax.crypto.Cipher&lt;/span&gt;.init(&lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;DashoA12275&lt;/span&gt;)&lt;br /&gt;        at &lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;org.jruby.ext.openssl.Cipher&lt;/span&gt;.doInitialize(&lt;span class=&quot;support support_type support_type_built-ins support_type_built-ins_java&quot;&gt;Cipher&lt;/span&gt;.java:&lt;span class=&quot;constant constant_numeric constant_numeric_java&quot;&gt;416&lt;/span&gt;)&lt;br /&gt;        at &lt;span class=&quot;storage storage_type storage_type_java&quot;&gt;org.jruby.ext.openssl.Cipher&lt;/span&gt;.update(&lt;span class=&quot;support support_type support_type_built-ins support_type_built-ins_java&quot;&gt;Cipher&lt;/span&gt;.java:&lt;span class=&quot;constant constant_numeric constant_numeric_java&quot;&gt;432&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby&quot;&gt;&amp;gt;&lt;/span&gt; ruby test_openssl_iv&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;rb &lt;br /&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Result&lt;/span&gt; is&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;:&lt;/span&gt; abc123 == abc123&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Yes, this is obviously an edge case, and one could argue that the Java implementation is more correct than MRI&#39;s, but the goal is any piece of code should run the same on either platform. &lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://headius.blogspot.com/&quot;&gt;Charles Nutter (Headius)&lt;/a&gt; has started a &lt;a href=&quot;http://www.headius.com/rubyspec/index.php/Main_Page&quot;&gt;RubySpec Wiki&lt;/a&gt; where I&#39;ve &lt;a href=&quot;http://www.headius.com/rubyspec/index.php/Openssl&quot;&gt;noted&lt;/a&gt; this issue there.  &lt;br /&gt;&lt;br /&gt;I&#39;ve submitted a &lt;a href=&quot;http://jira.codehaus.org/browse/JRUBY-1100&quot;&gt;bug&lt;/a&gt; against JRuby to track the issue, but arguably its not a JRuby bug. Its a difference between BouncyCastle and SSLeay&#39;s implementation.  I&#39;d be interested in some community feedback on how to correctly implement this.  For now, we&#39;ve worked around this by simply truncating if the RUBY_PLATFORM =~ /java/, which I know if horrible, but it allows me to move on.</description><link>http://revolutiononrails.blogspot.com/2007/06/ruby-vs-jruby-path-to-consistent.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-956084606226744783</guid><pubDate>Tue, 29 May 2007 03:29:00 +0000</pubDate><atom:updated>2007-05-29T07:15:36.779-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jmx</category><category domain="http://www.blogger.com/atom/ns#">jruby</category><title>Ruby-esque JMX -- Part 2</title><description>Below is the code from the JMX tinkering. I snake-ized the keys to be more Ruby-esque, per Ed&#39;s suggestion. &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_require meta_require_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;java&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Java&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; Obviously stolen from Rails ActiveSupport for underscoring strings&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;String&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;underscore&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_language variable_language_ruby&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;to_s&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;gsub&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_classic string_regexp_classic_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;::&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;br /&gt;    gsub&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_classic string_regexp_classic_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_group string_regexp_group_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_character-class string_regexp_character-class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;[&lt;/span&gt;A-Z&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;]&lt;/span&gt;&lt;/span&gt;+&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_character-class string_regexp_character-class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;[&lt;/span&gt;A-Z&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;][&lt;/span&gt;a-z&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;\1_\2&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;br /&gt;    gsub&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_classic string_regexp_classic_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_group string_regexp_group_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_character-class string_regexp_character-class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;[&lt;/span&gt;a-z&lt;span class=&quot;constant constant_character constant_character_escape constant_character_escape_ruby&quot;&gt;\d&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;string string_regexp string_regexp_character-class string_regexp_character-class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;[&lt;/span&gt;A-Z&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_character-class punctuation_definition_character-class_ruby&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_group punctuation_definition_group_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_ruby&quot;&gt;/&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;\1_\2&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;br /&gt;    tr&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;-&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;_&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;br /&gt;    downcase&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;JMX&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;MBean&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    include_class &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;javax.management.ObjectName&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    include_package &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;java.lang.management&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    include_package &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;javax.management&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    include_package &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;javax.management.remote&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    include_class &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;java.util.HashMap&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;attr_accessor&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;name&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;object_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;object_name&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; object_name &lt;br /&gt;      &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;name&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;object_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;to_s&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;attributes&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      attrs &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;connection&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;getMBeanInfo&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;object_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;attributes &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby&quot;&gt;[]&lt;/span&gt;&lt;br /&gt;      attrs&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;inject&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_block variable_other_block_ruby&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_block variable_other_block_ruby&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby&quot;&gt;|&lt;/span&gt;&lt;br /&gt;        list&lt;span class=&quot;punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby&quot;&gt;[&lt;/span&gt;a&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;underscore&lt;span class=&quot;punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;connection&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;getAttribute&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;object_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;a&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Unknown&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;        list&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.find_all_by_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      object_name &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ObjectName&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;      beans &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;connection&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;queryMBeans&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;object_name&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;      beans&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;collect &lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_block variable_other_block_ruby&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_variable punctuation_separator_variable_ruby&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;bean&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;get_object_name&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_scope punctuation_section_scope_ruby&quot;&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.find_by_name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;      &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;obviously inefficient&lt;br /&gt;&lt;/span&gt;      find_all_by_name&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;first&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.connection&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_class variable_other_readwrite_class_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@@&lt;/span&gt;mbsc&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby&quot;&gt;||=&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;        &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;load from some config file later maybe&lt;br /&gt;&lt;/span&gt;        url &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;        connector &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;JMXConnectorFactory&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;connect&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;JMXServiceURL&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;url&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;HashMap&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;        connector&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;getMBeanServerConnection&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;protected&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;method_missing&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;method&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;*&lt;/span&gt;args&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_object punctuation_separator_object_ruby&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_arithmetic keyword_operator_arithmetic_ruby&quot;&gt;&amp;amp;&lt;/span&gt;block&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      attributes&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;keys&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;include?&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;method&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;to_s&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;keyword keyword_operator keyword_operator_comparison keyword_operator_comparison_ruby&quot;&gt;?&lt;/span&gt; attributes&lt;span class=&quot;punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby&quot;&gt;[&lt;/span&gt;method&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;to_s&lt;span class=&quot;punctuation punctuation_section punctuation_section_array punctuation_section_array_ruby&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;super&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;Find all the MBeans matching some object name&lt;br /&gt;&lt;/span&gt;mbeans &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;JMX&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;find_all_by_name&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;java.lang:*&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;Found &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;mbeans&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;size&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt; beans&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;Find a bean, and get its attribute&lt;br /&gt;&lt;/span&gt;bean &lt;span class=&quot;keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;JMX&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_other punctuation_separator_other_ruby&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;find_by_name&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;java.lang:type=ClassLoading&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_function punctuation_section_function_ruby&quot;&gt;)&lt;/span&gt;&lt;br /&gt;puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;There are &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;bean&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_method punctuation_separator_method_ruby&quot;&gt;.&lt;/span&gt;loaded_class_count&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt; classes loaded in that VM&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;</description><link>http://revolutiononrails.blogspot.com/2007/05/ruby-esque-jmx-part-2.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-1851363431345948329</guid><pubDate>Fri, 25 May 2007 21:06:00 +0000</pubDate><atom:updated>2007-05-28T21:54:10.893-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jmx</category><category domain="http://www.blogger.com/atom/ns#">jruby</category><title>Ruby-esque JMX</title><description>The topic of JMX on JRuby came up recently and I decided to play around. I found a great starter on &lt;a href=&quot;http://jmesnil.net/weblog/2007/03/23/jmx-scripts-using-jruby/&quot;&gt;Jeff Mesnil&#39;s&lt;/a&gt; blog, but I decided I hated the syntax.&lt;br /&gt;&lt;br /&gt;Ruby has spoiled me. ActiveRecord has spoiled me.&lt;br /&gt;&lt;br /&gt;So I cooked up this little (fully working) example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span class=&quot;comment&quot;&gt;#Find all the MBeans matching some object name&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;ident&quot;&gt;mbeans&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;JMX&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;MBean&lt;/span&gt;&lt;span class=&quot;pun ct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;find_all_by_name&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;cacheStatistics:*&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;ident&quot;&gt;mbeans&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;bean&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&lt;span class=&quot;expr&quot;&gt;#{bean.name}&lt;/span&gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class=&quot;comment&quot;&gt;#Either use methods on the bean object&lt;/span&gt;&lt;br /&gt; &lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;  - CacheHits: &lt;span class=&quot;expr&quot;&gt;#{bean.CacheHits}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class=&quot;comment&quot;&gt;#Or access the attributes hash.&lt;/span&gt;&lt;br /&gt; &lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;  - CacheMisses: &lt;span class=&quot;expr&quot;&gt;#{bean.attributes[&quot;CacheHits&quot;]}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The code is ~50lines which I&#39;ll post at some point.&lt;br /&gt;&lt;br /&gt;I never thought working with java objects could be made to &quot;feel&quot; nice.&lt;br /&gt;&lt;br /&gt;I was also chatting with &quot;headius&quot; on #jruby, and he mentioned that &lt;a href=&quot;http://blog.springframework.com/rob/&quot;&gt;Rob Harrop&lt;/a&gt;, of Spring fame, had a &lt;a href=&quot;http://developers.sun.com/learning/javaoneonline/j1sessn.jsp?sessn=TS-9294&amp;yr=2007&amp;amp;track=9&quot;&gt;talk&lt;/a&gt; at JavaOne about  about something similar called MScript.  I&#39;d love to get my hands on those slides.</description><link>http://revolutiononrails.blogspot.com/2007/05/ruby-esque-jmx.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-1838940341863704348</guid><pubDate>Fri, 25 May 2007 15:54:00 +0000</pubDate><atom:updated>2007-05-25T12:50:21.881-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">activerecord</category><category domain="http://www.blogger.com/atom/ns#">acts_as</category><category domain="http://www.blogger.com/atom/ns#">db</category><category domain="http://www.blogger.com/atom/ns#">failure</category><title>Acts As Fast But Very Inaccurate Counter</title><description>&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If you have chosen the InnoDB MySQL engine over MyISAM for its support of transactions, foreign keys and other niceties, you might be aware of its limitations, like &lt;a href=&quot;http://www.mysqlperformanceblog.com/2006/12/01/count-for-innodb-tables/&quot;&gt;much slower count(*)&lt;/a&gt;. Our DBAs are in a constant lookout for slow queries in production and the ways to keep DBs happy so they recommended that we should try to fix count(). They suggested to check &lt;a href=&quot;http://dev.mysql.com/doc/refman/5.0/en/show-table-status.html&quot;&gt;&lt;i&gt;SHOW TABLE STATUS&lt;/i&gt;&lt;/a&gt; for an approximate count of rows in a table. This morning I wrote &lt;i&gt;acts_as_fast_counter&lt;/i&gt; which proved that the speed is indeed improved but the accuracy might be not acceptable. The rest of the post just records details of the exercise. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;The approach&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I created a model per engine and seeded each with 100K records. Then I run count on each model for a thousand times and measured the results.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The code:&lt;/b&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Acts&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_module entity_other_inherited-class_module_first entity_other_inherited-class_module_first_ruby&quot;&gt;ActiveRecord&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_module entity_other_inherited-class_module_second entity_other_inherited-class_module_second_ruby&quot;&gt;Acts&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;::&lt;/span&gt;&lt;/span&gt;ActsAsFastCounter&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.included&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    base.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ClassMethods&lt;/span&gt;)&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ClassMethods&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;acts_as_fast_counter&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;variable variable_language variable_language_ruby&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;FastCounterOverrides&lt;/span&gt;)&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;FastCounterOverrides&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;br /&gt;      &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;*args&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; args.empty?&lt;br /&gt;          connection.select_one(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;SHOW TABLE STATUS LIKE &#39;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;table_name &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&#39;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;)[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;Rows&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;].to_i&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;          &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;super&lt;/span&gt;(*args)&lt;br /&gt;        &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Base&lt;/span&gt;.send(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;include&lt;/span&gt;, &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Acts&lt;/span&gt;::&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ActsAsFastCounter&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :myisams, :options =&amp;gt; &#39;engine=MyISAM&#39;  do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :name, :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; 100_000.times { Myisam.create(:name =&amp;gt; Time.now.to_s) }&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :innodbs, :options =&amp;gt; &#39;engine=InnoDB&#39; do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :name, :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; 100_000.times { Innodb.create(:name =&amp;gt; Time.now.to_s) }&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;Bench&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_require meta_require_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;benchmark&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_require meta_require_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;acts_as_fast_counter&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.run&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    measure&lt;br /&gt;    show_count&lt;br /&gt;    convert_to_fast_counter&lt;br /&gt;    show_count&lt;br /&gt;    add_records&lt;br /&gt;    show_count&lt;br /&gt;    destroy_records&lt;br /&gt;    show_count&lt;br /&gt;    measure&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.measure&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;* Benchhmarks:&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    n = &lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;1_000&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Benchmark&lt;/span&gt;.bm(&lt;span class=&quot;constant constant_numeric constant_numeric_ruby&quot;&gt;12&lt;/span&gt;) &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|x|&lt;br /&gt;      x.report(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;MyISAM&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;) {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;n.times {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Myisam&lt;/span&gt;.count } }&lt;br /&gt;      x.report(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;InnoDB&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;) {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;n.times {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Innodb&lt;/span&gt;.count } }&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.convert_to_fast_counter&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Innodb&lt;/span&gt;.send(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;acts_as_fast_counter&lt;/span&gt;)&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;* Converted Innodb to fast counter&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.add_records&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;myisam&lt;/span&gt; = &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Myisam&lt;/span&gt;.create(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;name&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;One more&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;)&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;innodb&lt;/span&gt; = &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Innodb&lt;/span&gt;.create(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;name&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;One more&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;)&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;* Added records&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.destroy_records&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;myisam&lt;/span&gt;.destroy&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;innodb&lt;/span&gt;.destroy&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;* Destroyed records&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.show_count&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;* Record count:&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;    MyISAM: &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Myisam&lt;/span&gt;.count &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    puts &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;    InnoDB: &lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Innodb&lt;/span&gt;.count &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The results:&lt;/b&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;text text_plain&quot;&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Benchhmarks:&lt;br /&gt;&lt;/span&gt;                  &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;user     system      total        real&lt;br /&gt;MyISAM        0.180000   0.040000   0.220000 (  0.289983)&lt;br /&gt;InnoDB        0.430000   0.070000   0.500000 ( 35.102496)&lt;br /&gt;* Record count:&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;MyISAM: 100000&lt;br /&gt;    InnoDB: 100000&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Converted Innodb to fast counter&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Record count:&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;MyISAM: 100000&lt;br /&gt;    InnoDB: 100345&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Added records&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Record count:&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;MyISAM: 100001&lt;br /&gt;    InnoDB: 100345&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Destroyed records&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Record count:&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;MyISAM: 100000&lt;br /&gt;    InnoDB: 100345&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_bullet-point meta_bullet-point_star&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_item punctuation_definition_item_text&quot;&gt;*&lt;/span&gt; Benchhmarks:&lt;br /&gt;&lt;/span&gt;                  &lt;span class=&quot;meta meta_paragraph meta_paragraph_text&quot;&gt;user     system      total        real&lt;br /&gt;MyISAM        0.250000   0.030000   0.280000 (  0.350673)&lt;br /&gt;InnoDB        0.250000   0.040000   0.290000 (  0.977711)&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Final thoughts&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The MySQL manual has a clear warning about inaccuracy of the amount of rows in the &lt;i&gt;SHOW TABLE STATUS&lt;/i&gt; results: &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;Rows - The number of rows. Some storage engines, such as MyISAM, store the exact count. For other storage engines, such as InnoDB, this value is an approximation, and may vary from the actual value by as much as 40 to 50%. In such cases, use SELECT COUNT(*) to obtain an accurate count.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;The test confirms it by showing 345 more records then expected thus making it not very useful but for some edge cases. If you know a way to improve the speed of &lt;i&gt;count()&lt;/i&gt; on InnoDB with some other approach beyond using a counter table, please share.</description><link>http://revolutiononrails.blogspot.com/2007/05/acts-as-fast-but-very-inaccurate.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-3879796053507920259</guid><pubDate>Thu, 24 May 2007 21:26:00 +0000</pubDate><atom:updated>2007-05-24T16:01:47.287-07:00</atom:updated><title>Javascript: Event.onElementReady</title><description>We deal with a lot of Javascript at RHG.  Rather then create functional one-offs that become hard to maintain and very duplicative, we prefer to have collections of behavior that can be assigned to parts of the document.  Our CSS designers especially like this because it makes our markup clean and easy to read.  It also means we can have tests that exercise a series of interactions.&lt;br /&gt;&lt;br /&gt;However, there is a problem we run into when loading the page over a slow connection: the Javascript is not run until window.onload, meaning our users suffer as they can see part of the page rendered but not use it until it&#39;s fully loaded.  For those who don&#39;t know, window.onload will not execute until all images, CSS, and Javascript files have loaded.  Our first solution to this problem was to use &lt;a href=&quot;http://dean.edwards.name/weblog/2006/06/again/&quot;&gt;onDOMReady&lt;/a&gt;.  This has worked fairly well and kept our site running reasonably quickly.  We&#39;ve run into problems with onDOMReady in IE6 however, and as a result disabled it in favor of having our pages render all the time.  In the IE family of browsers if a script tries to access a part of the DOM before it has been completely processed the browser will raise an exception &lt;a href=&quot;http://weblogs.asp.net/infinitiesloop/archive/2006/11/02/Dealing-with-IE-_2600_quot_3B00_Operation-Aborted_2600_quot_3B002E00_-Or_2C00_-how-to-Crash-IE.aspx&quot;&gt;&quot;operation aborted&quot;&lt;/a&gt;. After this alert message pops up, the web page becomes unusable and the browser could even crash.&lt;br /&gt;&lt;br /&gt;After some careful thinking we decided we would attach our behavior objects in smaller chunks of the DOM.  Rather then wait until the window.onload or onDomReady events fire we can use a few inline script tags that call a function that figures out how to attach itself to its most immediate &lt;a href=&quot;http://developer.mozilla.org/en/docs/DOM:element.parentNode&quot;&gt;parentNode&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;For example, we do this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;&lt;span class=&quot;keyword&quot;&gt;div&lt;/span&gt; class=&lt;span class=&quot;comment&quot;&gt;&quot;parent&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;span class=&quot;keyword&quot;&gt;div&lt;/span&gt; class=&lt;span class=&quot;comment&quot;&gt;&quot;bvr-blah&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;   &amp;lt;/&lt;span class=&quot;keyword&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;span class=&quot;keyword&quot;&gt;script&lt;/span&gt; type=&lt;span class=&quot;comment&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;     RHG.Behavior.&lt;span class=&quot;function&quot;&gt;attach&lt;/span&gt;();&lt;br /&gt;   &amp;lt;/&lt;span class=&quot;keyword&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;span class=&quot;keyword&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;There could be multiple behaviors in the above block of markup that are all contained within the hypothetical div.parent element.&lt;br /&gt;&lt;br /&gt;Now, to allow this to work the div.parent must be ready.  Otherwise, IE will cancel the whole page rendering with the &quot;Operation Aborted&quot; alert.&lt;br /&gt;&lt;br /&gt;Event.onElementReady checks for features of the DOM element to determine whether or not the element is really ready to be manipulatd.  Thankfully, IE doesn&#39;t mind if you read from an element before it&#39;s ready only if you try and modify it.  This method will poll the DOM element until either the &lt;a href=&quot;http://developer.mozilla.org/en/docs/DOM:element.nextSibling&quot;&gt;nextSibling&lt;/a&gt; or the &lt;a href=&quot;http://developer.mozilla.org/en/docs/DOM:element.textContent&quot;&gt;textContent&lt;/a&gt; is non null.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;span class=&quot;keyword&quot;&gt;Object&lt;/span&gt;.extend(&lt;span class=&quot;keyword&quot;&gt;Event&lt;/span&gt;,{&lt;br /&gt; &lt;span class=&quot;comment&quot;&gt;// check whether or not the DOM element is ready&lt;/span&gt;&lt;br /&gt; &lt;span class=&quot;function&quot;&gt;onElementReady&lt;/span&gt;: &lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(element,callback)&lt;br /&gt; {&lt;br /&gt;   &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;( element &amp;&amp;amp; (element.nextSibling || element.textContent) ){&lt;br /&gt;     callback();&lt;br /&gt;   }&lt;br /&gt;   &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt;{&lt;br /&gt;     setTimeout( &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.onElementReady.bind(this,element,callback), 1 );&lt;br /&gt;   }&lt;br /&gt; }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now we can attach our behaviors as the page is rendering and avoid &quot;Operation Aborted&quot; alerts from IE.</description><link>http://revolutiononrails.blogspot.com/2007/05/javascript-eventonelementready.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-6731017440028182401</guid><pubDate>Wed, 23 May 2007 01:33:00 +0000</pubDate><atom:updated>2007-05-22T17:09:17.593-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">controller</category><category domain="http://www.blogger.com/atom/ns#">dry</category><category domain="http://www.blogger.com/atom/ns#">edge</category><category domain="http://www.blogger.com/atom/ns#">polymorphic</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">resource</category><title>DRYing Up Polymorphic Controllers</title><description>Polymorphic routes allow drying up the controller implementation when functionality is identical, regardless of entry point. A good example is comments for articles and blogs. There is a challenge to balance the implementation of the comments controller reflecting the multiple incoming routes. Let&#39;s look at the way it could be written.&lt;br /&gt;&lt;br /&gt;Routing is straightforward with blogs and article models &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/05/drying-models-via-acts-as.html&quot;&gt;acting as commentable&lt;/a&gt; and both the comment model and comment controllers being polymorphic:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActionController&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Routing&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Routes&lt;/span&gt;.draw &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|map|&lt;br /&gt;  map.resources &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;articles&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;has_many&lt;/span&gt; =&amp;gt; [ &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;comments&lt;/span&gt; ]&lt;br /&gt;  map.resources &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;blogs&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;has_many&lt;/span&gt; =&amp;gt; [ &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;comments&lt;/span&gt; ]&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This means that a comment can be created via post to either &lt;i&gt;/&lt;b&gt;articles&lt;/b&gt;/1/comments/new&lt;/i&gt; or &lt;i&gt;/&lt;b&gt;blogs&lt;/b&gt;/1/comments/new&lt;/i&gt;. The comments controller can be implemented to handle both:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_rails meta_rails_controller&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;CommentsController&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ApplicationController&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt; = parent_object&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt; = &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Comment&lt;/span&gt;.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;create&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt; = parent_object&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt; = &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt;.comments.build(params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;comment&lt;/span&gt;])&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt;.valid? &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt;.save&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;redirect_to&lt;/span&gt; parent_url(&lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt;)&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;action&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;new&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;private&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_object&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;case&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;when&lt;/span&gt; params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;article_id&lt;/span&gt;] &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Article&lt;/span&gt;.find_by_id(params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;article_id&lt;/span&gt;])&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;when&lt;/span&gt; params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;news_id&lt;/span&gt;] &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;News&lt;/span&gt;.find_by_id(params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;news_id&lt;/span&gt;])&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;    &lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;  &lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_url&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;case&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;when&lt;/span&gt; params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;article_id&lt;/span&gt;] &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;then&lt;/span&gt; article_url(parent)&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;when&lt;/span&gt; params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;news_id&lt;/span&gt;] &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;then&lt;/span&gt; news_url(parent)&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;    &lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This method works fine and there is not much drive to start refactoring it right away. This changes, though, if there is a need to add another commentable or allow some other polymorphic route. Instead of adding more &#39;when&#39; clauses the whole functionality can be extracted and abstracted based on the idea of having fixed naming conventions for resources that allow movement from a controller name to a model. The refactored example has the parent functionality extracted to the application controller to share it as-is with other polymorphic routes:&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_rails meta_rails_controller&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;ApplicationController&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ActionController::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;protected&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;&lt;span class=&quot;variable variable_other variable_other_object variable_other_object_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; self&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;    &lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;attr_reader&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;parents&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_resources&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;*parents&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parents&lt;/span&gt; = parents&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_id&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    request.path_parameters[&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;parent &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;_id&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_type&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_language variable_language_ruby&quot;&gt;self&lt;/span&gt;.class.parents.detect {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|parent| parent_id(parent) }&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_class&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    parent_type &amp;amp;&amp;amp; parent_type.to_s.classify.constantize&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;   &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;parent_object&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    parent_class &amp;amp;&amp;amp; parent_class.find_by_id(parent_id(parent_type))&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_rails meta_rails_controller&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;CommentsController&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ApplicationController&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  parent_resources &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;article&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;blogs&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt; = parent_object&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt; = &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Comment&lt;/span&gt;.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;create&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt; = parent_object&lt;br /&gt;    &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt; = &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt;.comments.build(params[&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;comment&lt;/span&gt;])&lt;br /&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt;.valid? &lt;span class=&quot;keyword keyword_operator keyword_operator_logical keyword_operator_logical_ruby&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;comment&lt;/span&gt;.save&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;redirect_to&lt;/span&gt; send(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;parent_type &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;_url&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;variable variable_other variable_other_readwrite variable_other_readwrite_instance variable_other_readwrite_instance_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_variable punctuation_definition_variable_ruby&quot;&gt;@&lt;/span&gt;parent&lt;/span&gt;)&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;else&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_actionpack support_function_actionpack_rails&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;action&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;new&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;i&gt;parent_resources&lt;/i&gt; call declares resources that are parent for a current controller. An alternative approach is to guess such parent resources from the request URI and routes. Aaron is currently working on a patch on Edge implementing it. We&#39;ll update this post later.&lt;br /&gt;&lt;br /&gt;If you currently use multiple polymorphic resources and have &lt;i&gt;if&lt;/i&gt; clauses in the controller code, you might want to rethink how it could be DRYed up using this approach. In some cases views are very parent type specific. Then it might be better to have different templates and partials rendered via &lt;i&gt;render :template =&gt; &quot;/controller/#{ parent_type }_action&quot;&lt;/i&gt;.</description><link>http://revolutiononrails.blogspot.com/2007/05/drying-up-polymorphic-controllers.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>15</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-4742813974354373895</guid><pubDate>Mon, 14 May 2007 16:10:00 +0000</pubDate><atom:updated>2007-05-14T10:12:11.102-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">capistrano</category><category domain="http://www.blogger.com/atom/ns#">deployment</category><category domain="http://www.blogger.com/atom/ns#">gems</category><category domain="http://www.blogger.com/atom/ns#">plugem</category><category domain="http://www.blogger.com/atom/ns#">rhg</category><title>Capistrano Off the Beaten Path</title><description>&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If you use Capistrano, most likely you use it to deploy rails applications by running it from the project directory. The &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/05/release-plugems-packaging.html&quot;&gt;plugem management tool&lt;/a&gt; piggy-backs on Capistrano to execute some recipes without using the current path because recipes operate on gems. Recipes do not, however, completely ignore the current directory, but instead use it for optional customization. Customization is not limited to a deployment recipe from the current directory but can be environment-specific across multiple sites if they each have a special extension gem installed.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Background&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/03/when-capistrano-is-not-enough.html&quot;&gt;We use a bunch of ruby scripts at RHG&lt;/a&gt; for deployment and delivery of our numerous applications and shared component. When we started preparing some of that functionality for a public release, we needed to provide a way to customize the scripts. &lt;a href=&quot;http://workingwithrails.com/person/8407-warren-konkel&quot;&gt;Warren Konkel&lt;/a&gt; suggested to migrate them to Capistrano since it was the most familiar tool for rails developers and it has a recipes hierarchy that can be used for customization. So, we wrote the &lt;i&gt;plugem&lt;/i&gt; command tool that feeds its parameters to Capistrano via &lt;i&gt;Capistrano::CLI.new(plugem_converted_arguments).execute!&lt;/i&gt;&lt;br /&gt;after loading its own recipes.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;linenum&quot;&gt;    1&lt;/span&gt; &lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;Capistrano&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    2&lt;/span&gt; &lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;Configuration&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    3&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    4&lt;/span&gt;     &lt;span class=&quot;keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;standard_cap_load&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;load&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    5&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    6&lt;/span&gt;     &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;*args, &amp;block&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    7&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    8&lt;/span&gt;       standard_cap_load(*args, &amp;amp;block)&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;    9&lt;/span&gt;      &lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   10&lt;/span&gt;       &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;if&lt;/span&gt; args == [&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;standard&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   11&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   12&lt;/span&gt;         load_plugem_deploy_recipes(&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.dirname(&lt;span class=&quot;variable variable_language variable_language_ruby&quot;&gt;__FILE__&lt;/span&gt;) + &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;/../..&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;)&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   13&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   14&lt;/span&gt;         &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   15&lt;/span&gt;           &lt;span class=&quot;meta meta_require meta_require_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;plugems_deploy_ext&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   16&lt;/span&gt;           load_plugem_deploy_recipes(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;PLUGEMS_DEPLOY_EXT_DIR&lt;/span&gt;) &lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; Overriding from extensions&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;linenum&quot;&gt;   17&lt;/span&gt;         &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Exception&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   18&lt;/span&gt; &lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;          &lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; No extension is loaded&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;linenum&quot;&gt;   19&lt;/span&gt;         &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   20&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   21&lt;/span&gt;       &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   22&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   23&lt;/span&gt;     &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   24&lt;/span&gt;    &lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   25&lt;/span&gt;     &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;load_plugem_deploy_recipes&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   26&lt;/span&gt;       &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Dir&lt;/span&gt;[&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;File&lt;/span&gt;.join(dir, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;recipes&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;*&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;)].each {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|f| standard_cap_load(f) }&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   27&lt;/span&gt;     &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   28&lt;/span&gt;      &lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   29&lt;/span&gt;   &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;linenum&quot;&gt;   30&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Ignoring lines 14-19 for now, all it does is inject the plugem deployment gem recipes to Capistrano. They are now available for execution by Capistrano. So when I call &lt;i&gt;plugem update my_app&lt;/i&gt; it is being translated to &lt;i&gt;cap plugem_update -s plugem_name=my_app&lt;/i&gt;(we use the &lt;i&gt;plugem_&lt;/i&gt; namespace for tasks and variables to avoid clashing with standard recipes). Since loading of plugem recipes is purposely not handled via the &lt;i&gt;-f&lt;/i&gt; flag of capistrano, the standard deployment recipes like &lt;i&gt;config/deploy.rb&lt;/i&gt; are still being loaded.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Customization&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The package is extending Capistrano but we wanted it to be customized too. For example, you might want to define your own list of gem servers to download gems from. Capistrano allows to define recipes per project, user, or host. The plugems_deploy takes it a step further and provides a way to customize it per deployment environment, which might contain many hosts. It does this by expecting an optional &lt;i&gt;plugems_deploy_ext&lt;/i&gt; gem to be installed on a system (lines 14-19). If it finds the extension gem, it loads recipes from there overriding the default ones.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Capistrano is not only a great deployment tool, it can be used as a base of highly-customizable general purpose tools.</description><link>http://revolutiononrails.blogspot.com/2007/05/capistrano-off-beaten-path.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-2873495419095678807</guid><pubDate>Fri, 11 May 2007 18:14:00 +0000</pubDate><atom:updated>2007-05-11T11:32:40.287-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">activerecord</category><category domain="http://www.blogger.com/atom/ns#">db</category><category domain="http://www.blogger.com/atom/ns#">migrations</category><category domain="http://www.blogger.com/atom/ns#">plugin</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">tips</category><title>Plugin I Cannot Live Without</title><description>&lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/02/plugin-release-enhanced-rails.html&quot;&gt;The Enhanced Rails Migrations plugin&lt;/a&gt; was written to end the constant battle we had with clashing names in db migrations within our large development team. We tried everything: special commit policies, rake tasks, even claiming the next migration number in subversion. Nothing worked and CI server was sending &#39;broken build due to conflicting migration number&#39; messages almost daily. Since the plugin was introduced to all our rails applications around six months ago, I have not heard of a single case of conflicting migrations. Seemingly, the goal was well accomplished.&lt;br /&gt;&lt;br /&gt;What I found over time, is that the plugin is not only useful for large projects. Any rails development effort with more than one programmer involved benefits from using it. If you ever had to renumber your new migration after doing &lt;i&gt;svn up&lt;/i&gt; you know what I am talking about. It makes sense to install this plugin as the very first one in your project since an amount of migrations at the beginning tends to grow much faster then later in the game.&lt;br /&gt;&lt;br /&gt;The plugin works for rails versions 1.1.6 up to the latest edge. When you start your next project with multiple developers, use it and you should be able to forget that you ever had problems with clashing migrations.</description><link>http://revolutiononrails.blogspot.com/2007/05/plugin-i-cannot-live-without.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-2823848440432083233</guid><pubDate>Wed, 09 May 2007 14:26:00 +0000</pubDate><atom:updated>2007-05-13T20:29:42.485-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">activerecord</category><category domain="http://www.blogger.com/atom/ns#">acts_as</category><category domain="http://www.blogger.com/atom/ns#">db</category><category domain="http://www.blogger.com/atom/ns#">migrations</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">tips</category><title>Moving models to a different database</title><description>There many reasons to use multiple databases (DBs) and when this is done, there is often a case when a model needs to be moved from one DB to another. The impetus could be that part of the data is referential and this is being reflected by moving it to a read-only DB. Another possibility is that we want to protect some data with an additional layer of security, so we extract it to a secure DB. In all cases, the challenge is to migrate the existing data. When the amount of data is considerably large, there is no choice but to do it via &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/02/data-loaders-in-migrations.html&quot;&gt;SQL data loaders&lt;/a&gt; or similar techniques. On the other hand, if it is acceptable to leverage rails db migrations and you prefer to do any data manipulation through them, there are some challenges to face.&lt;br /&gt;&lt;br /&gt;Often, you need to have an access to old and new models during data migration. One solution is to move or copy an existing model to a separate namespace and put the new model instead at the old namespace. Let&#39;s look at a couple of examples:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Extracting referential data&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I have a model &lt;i&gt;Fruit&lt;/i&gt; in our main DB which gets its data from an external source, so we only access it read-only. We want to enforce it by moving the data to a DB which we access with a read-only account. First, I create a &lt;i&gt;referential_db&lt;/i&gt; entry in database.yml:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_yaml&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;dbs&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;  &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;database&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;main&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;referential_db&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;database&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;referential&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Then, I copy the original model, &lt;i&gt;Fruit&lt;/i&gt;, to a dedicated namespace, so the model becomes &lt;i&gt;RetiredModels::Fruit&lt;/i&gt;. I add &lt;i&gt;establish_connection&lt;/i&gt; to the original namespace model:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :fruits do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :name, :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_rails meta_rails_model&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;Fruit&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  establish_connection configurations[&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;RAILS_ENV&lt;/span&gt;][&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;referential_db&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;]  &lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Everything is set for migration. Since it is a referential data, the migration needs to preserve data integrity so the models belonging to &lt;i&gt;Fruit&lt;/i&gt; can still reference it by an old id:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.up&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;RetiredModels&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Fruit&lt;/span&gt;.find(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;all&lt;/span&gt;).each &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|old_record|&lt;br /&gt;    &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Fruit&lt;/span&gt;.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;new&lt;/span&gt;(old_record.attributes) {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|new_record| new_record.id = old_record.id }.save!&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;After the successful migration run, all data is replicated to a new DB. The retired model can be removed during next deployment, and the original table dropped.&lt;br /&gt;&lt;br /&gt;There is one caveat for development and test modes. If you don&#39;t want to bother with multiple databases in those modes, you need to take care of having no table name clashing. So, the new model would have to use different table names via &lt;i&gt;set_table_name&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Securing sensitive data&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;One of the models belonging to &lt;i&gt;Fruit&lt;/i&gt; is &lt;i&gt;SecretFruit&lt;/i&gt;. It contains a secret name for every fruit out there. Our legal department asked the development team to protect that data in case our DB is stolen. We decided to migrate the existing SecretFruit data to a protected DB and keep sensitive data encrypted with help from &lt;a href=&quot;http://revolutiononrails.blogspot.com/2007/04/plugin-release-actsassecure.html&quot;&gt;Acts As Secure&lt;/a&gt;. First, I create a &lt;i&gt;secure_db&lt;/i&gt; entry in database.yml:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_yaml&quot;&gt;&lt;span class=&quot;meta meta_tag meta_tag_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;dbs&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;  &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;database&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;main&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span class=&quot;meta meta_tag meta_tag_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;secure_db&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;    &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;database&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;secure&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;&lt;span class=&quot;entity entity_name entity_name_tag entity_name_tag_yaml&quot;&gt;host&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_yaml&quot;&gt;:&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;string string_unquoted string_unquoted_yaml&quot;&gt;protected_host&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Then, I copy the original model, &lt;i&gt;SecretFruit&lt;/i&gt;, to a dedicated namespace, so the model becomes &lt;i&gt;RetiredModels::SecretFruit&lt;/i&gt;. I modify the model in the original namespace to reflect the new requirements:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :secret_fruits do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :name, :binary&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :fruit_id, :integer&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_rails meta_rails_model&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;SecretFruit&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  establish_connection configurations[&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;RAILS_ENV&lt;/span&gt;][&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;secure_db&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;]&lt;br /&gt;  acts_as_secure &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;crypto_provider&lt;/span&gt; =&amp;gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;MasterKeyProvider&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;fruit&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Since data encryption is done on-the-fly and there are no data integrity requirements, the migration is straightforward:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.up&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;RetiredModels&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;SecretFruit&lt;/span&gt;.find(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;all&lt;/span&gt;).each {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|old| &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;SecretFruit&lt;/span&gt;.create!(old.attributes) }&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;I can now safely delete &lt;i&gt;RetiredModels::SecretFruit&lt;/i&gt; and associated data.</description><link>http://revolutiononrails.blogspot.com/2007/05/moving-models-to-different-database.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-5106153650083006834</guid><pubDate>Tue, 08 May 2007 04:44:00 +0000</pubDate><atom:updated>2007-05-09T12:41:26.755-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">activerecord</category><category domain="http://www.blogger.com/atom/ns#">acts_as</category><category domain="http://www.blogger.com/atom/ns#">dry</category><category domain="http://www.blogger.com/atom/ns#">refactoring</category><category domain="http://www.blogger.com/atom/ns#">tips</category><title>DRYing Models via Acts As</title><description>&lt;i&gt;ActsAs&lt;/i&gt; is an idiom familiar to every Rails developer, which makes it a good candidate for a shared functionality between models. Using it as early in the game as possible allows one to work on its functionality without a need to touch the code in multiple models. Let&#39;s look at a couple of examples.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Acts As Unique&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I have some models that I want to have uniqueness across my application. I use some UUID mechanism (initially, a db call) to set a field (&lt;i&gt;:token&lt;/i&gt;) after creation. Since I have multiple models, I decide to extract it the code for uniqueness setting to &lt;i&gt;acts_as_unique&lt;/i&gt;. After refactoring, my model &lt;i&gt;Fruit&lt;/i&gt; looks like:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :fruits do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :name, :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :token, :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_rails meta_rails_model&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;Fruit&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  acts_as_unique&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;My &lt;i&gt;acts_as_unique&lt;/i&gt; might look like:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Acts&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_module entity_other_inherited-class_module_first entity_other_inherited-class_module_first_ruby&quot;&gt;ActiveRecord&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_module entity_other_inherited-class_module_second entity_other_inherited-class_module_second_ruby&quot;&gt;Acts&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;::&lt;/span&gt;&lt;/span&gt;ActsAsUnique&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.included&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    base.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ClassMethods&lt;/span&gt;)&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ClassMethods&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;acts_as_unique&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;field = &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;token&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;validates_uniqueness_of&lt;/span&gt; field &lt;br /&gt;      &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;before_validation_on_create&lt;/span&gt; &lt;span class=&quot;keyword keyword_control keyword_control_ruby keyword_control_ruby_start-block&quot;&gt;do &lt;/span&gt;|o|&lt;br /&gt;        o.send(&lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;field &lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt;=&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;, connection.select_one(&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;SELECT UUID() AS UUID&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;string string_quoted string_quoted_double string_quoted_double_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;source source_ruby source_ruby_embedded source_ruby_embedded_source&quot;&gt;&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;#{&lt;/span&gt;name&lt;span class=&quot;punctuation punctuation_section punctuation_section_embedded punctuation_section_embedded_ruby&quot;&gt;}&lt;/span&gt;&lt;/span&gt; UUID generated&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;)[&lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;UUID&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;])&lt;br /&gt;      &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;    &lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Base&lt;/span&gt;.send(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;include&lt;/span&gt;, &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Acts&lt;/span&gt;::&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ActsAsUnique&lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Let&#39;s try it:&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; f = Fruit.create(:name =&gt; &#39;apple&#39;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; p f.token&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&quot;0a4d7c46-4df0-102a-a4b9-59b995bffdb7&quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now I can work on &lt;i&gt;acts_as_unique&lt;/i&gt; to replace the DB call with a UUID gem or some other implementation without affecting the rest of the code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Acts As Trackable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I have some models for which I want to keep track of when instances are created or updated. I have a polymorphic &lt;i&gt;Event&lt;/i&gt; model for storage of such events. Since there are multiple models I want to track, I extract the functionality to &lt;i&gt;acts_as_trackable&lt;/i&gt;. After refactoring, my models look like:&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :fruits do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column :name, :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_rails meta_rails_model&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;Fruit&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  acts_as_trackable&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; create_table :events do |t|&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column &quot;action&quot;,              :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column &quot;created_at&quot;,          :datetime, :null =&amp;gt; false&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column &quot;trackable_type&quot;,      :string&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt;   t.column &quot;trackable_id&quot;,        :integer&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;comment comment_line comment_line_number-sign comment_line_number-sign_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_ruby&quot;&gt;#&lt;/span&gt; end&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;meta meta_rails meta_rails_model&quot;&gt;&lt;span class=&quot;meta meta_class meta_class_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_class keyword_control_class_ruby&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby&quot;&gt;Event&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_ruby&quot;&gt; &lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;br /&gt;  &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;trackable&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;polymorphic&lt;/span&gt; =&amp;gt; &lt;span class=&quot;constant constant_language constant_language_ruby&quot;&gt;true&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre class=&quot;textmate-source blackboard&quot;&gt;&lt;span class=&quot;source source_ruby source_ruby_rails&quot;&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ActiveRecord&lt;/span&gt;&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;Acts&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;; &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt; &lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_module entity_other_inherited-class_module_first entity_other_inherited-class_module_first_ruby&quot;&gt;ActiveRecord&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;::&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;entity entity_other entity_other_inherited-class entity_other_inherited-class_module entity_other_inherited-class_module_second entity_other_inherited-class_module_second_ruby&quot;&gt;Acts&lt;span class=&quot;punctuation punctuation_separator punctuation_separator_inheritance punctuation_separator_inheritance_ruby&quot;&gt;::&lt;/span&gt;&lt;/span&gt;ActsTrackable&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;  &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;self.included&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;variable variable_parameter variable_parameter_function variable_parameter_function_ruby&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_parameters punctuation_definition_parameters_ruby&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    base.&lt;span class=&quot;keyword keyword_other keyword_other_special-method keyword_other_special-method_ruby&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ClassMethods&lt;/span&gt;)&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;meta meta_module meta_module_ruby&quot;&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_module keyword_control_module_ruby&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby&quot;&gt;ClassMethods&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby&quot;&gt;&lt;span class=&quot;keyword keyword_control keyword_control_def keyword_control_def_ruby&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;entity entity_name entity_name_function entity_name_function_ruby&quot;&gt;acts_as_trackable&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;has_many&lt;/span&gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;events&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;as&lt;/span&gt; =&amp;gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;trackable&lt;/span&gt;, &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;dependent&lt;/span&gt; =&amp;gt; &lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;destroy&lt;/span&gt;&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;after_update&lt;/span&gt; {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|o| o.events.create(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;action&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;updated&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;) }&lt;br /&gt;      &lt;span class=&quot;support support_function support_function_activerecord support_function_activerecord_rails&quot;&gt;after_create&lt;/span&gt; {&lt;span class=&quot;meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block&quot;&gt; &lt;/span&gt;|o| o.events.create(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;action&lt;/span&gt; =&amp;gt; &lt;span class=&quot;string string_quoted string_quoted_single string_quoted_single_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_ruby&quot;&gt;&#39;&lt;/span&gt;created&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_ruby&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;) }&lt;br /&gt;    &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;keyword keyword_control keyword_control_ruby&quot;&gt;end&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Base&lt;/span&gt;.send(&lt;span class=&quot;constant constant_other constant_other_symbol constant_other_symbol_ruby&quot;&gt;&lt;span class=&quot;punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_ruby&quot;&gt;:&lt;/span&gt;include&lt;/span&gt;, &lt;span class=&quot;support support_class support_class_ruby&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;support support_class support_class_ruby&quot;&gt;Acts&lt;/span&gt;::&lt;span class=&quot;variable variable_other variable_other_constant variable_other_constant_ruby&quot;&gt;ActsTrackable&lt;/span&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;Let&#39;s see what we got:&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; f = Fruit.create(:name =&gt; &#39;apple&#39;)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; p f.events.collect(&amp;:action)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;[&quot;created&quot;]&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; f.name = &#39;passionfruit&#39;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; f.save!&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;&gt;&gt; p f.events.collect(&amp;amp;:action)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family:courier new;&quot;&gt;[&quot;created&quot;, &quot;updated&quot;]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Event model is likely to evolve but it would be easier to support it since the only place where I need to reflect the changes is &lt;i&gt;acts_as_trackable&lt;/i&gt;. The goal is achieved.</description><link>http://revolutiononrails.blogspot.com/2007/05/drying-models-via-acts-as.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-4690871303856834654</guid><pubDate>Wed, 02 May 2007 20:52:00 +0000</pubDate><atom:updated>2007-05-26T10:42:19.783-07:00</atom:updated><title>CSS: CSS Browser Selector</title><description>&lt;p&gt;&lt;br /&gt;Each browser has its quirks.   Having a clear way of organizing the work arounds&lt;br /&gt;for those quirks is a challenge.   Using CSS selectors is not a new idea, but I thought it might be helpful to others to give an example of the technique and how we&#39;ve been able to successfully deploy it for &lt;a title=&quot;Revolution Health&quot; href=&quot;http://www.revolutionhealth.com/&quot;&gt;revolutionhealth.com&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;First, for IE (the browser that usually requires a hack), we can rely on conditional comments.  This is good because it means we don&#39;t need to depend on Javascript.  For other browsers we&#39;ll have to rely on a document.write solution.   For Safari, Opera, and Firefox, we rely on the script from &lt;a title=&quot;CSS Browser Selector&quot; href=&quot;http://rafael.adm.br/css_browser_selector/&quot;&gt;http://rafael.adm.br/css_browser_selector/&lt;/a&gt; and for IE, conditional comments. &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Here&#39;s what we include at the top of our document.  (The browser_detect_start partial.)&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;!--[if lt IE 7.]&amp;gt;&lt;br /&gt;&amp;lt;div class=&#39;ie ie6&#39;&amp;gt;&lt;br /&gt;&amp;lt;![endif]--&amp;gt;&lt;br /&gt;&amp;lt;!--[if IE 7]&amp;gt;&lt;br /&gt;&amp;lt;div class=&#39;ie ie7&#39;&amp;gt;&lt;br /&gt;&amp;lt;![endif]--&amp;gt;&lt;br /&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;//&amp;lt;![CDATA[&lt;br /&gt; var d = browserCSSDetection();&lt;br /&gt; if( d.browser != &quot;ie&quot; ){ document.write( &quot;&amp;lt;div class=&#39;&quot; + d.browser + &quot; &quot; + d.os + &quot;&#39;&amp;gt;&quot; ); }&lt;br /&gt;//]]&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And here&#39;s what we do for the end of the document. (The browser_detect_end partial.)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;!--[if IE ]&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;![endif]--&amp;gt;&lt;br /&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;//&amp;lt;![CDATA[&lt;br /&gt; var d = browserCSSDetection();&lt;br /&gt; if( d.browser != &quot;ie&quot; ){ document.write( &quot;&amp;lt;/div&amp;gt;&quot; ); }&lt;br /&gt;//]]&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;The browser detection in Javascript.  This could be enhanced further, but for us this allowed us to get the site working relatively easy in &lt;a title=&quot;Konqueror - Web Browser, File Manager - and more!&quot; href=&quot;http://www.konqueror.org/&quot;&gt;Konqueror&lt;/a&gt;.  As well it enabled us to fix our menu&#39;s so that they float over flash in Linux using &lt;a title=&quot;HTML div above a Flash animation on Linux - it’s possible!&quot; href=&quot;http://blog.marcoos.com/2006/07/21/html-div-above-a-flash-animation-on-linux-its-possible/&quot;&gt;this&lt;/a&gt; techinque.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function browserCSSDetection()&lt;br /&gt;{&lt;br /&gt; // see: http://rafael.adm.br/css_browser_selector/&lt;br /&gt; var ua = navigator.userAgent.toLowerCase();&lt;br /&gt; var is = function(t){ return ua.indexOf(t) != -1; };&lt;br /&gt; var b = (!(/opera|webtv/i.test(ua))&amp;&amp;amp;/msie (\d)/.test(ua)) ?&lt;br /&gt;             (&#39;ie ie&#39;+RegExp.$1) :&lt;br /&gt;               is(&#39;gecko/&#39;) ? &#39;gecko&#39; :&lt;br /&gt;               is(&#39;opera/9&#39;) ? &#39;opera opera9&#39; :&lt;br /&gt;               /opera (\d)/.test(ua) ? &#39;opera opera&#39;+RegExp.$1 :&lt;br /&gt;               is(&#39;konqueror&#39;)?&#39;konqueror&#39; :&lt;br /&gt;               is(&#39;applewebkit/&#39;) ? &#39;webkit safari&#39;:&lt;br /&gt;               is(&#39;mozilla/&#39;)?&#39;gecko&#39;:&#39;&#39;;&lt;br /&gt; // see: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html&lt;br /&gt; var os = (is(&#39;x11&#39;)||is(&#39;linux&#39;))?&#39; linux&#39;:is(&#39;mac&#39;)?&#39; mac&#39;:is(&#39;win&#39;)?&#39; win&#39;:&#39;&#39;;&lt;br /&gt; var css = {browser:b,os:os};&lt;br /&gt; return css;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Finally, to make all this fit nicely into a layout:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;%= javascript_include_tag &#39;browser_detect&#39; %&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;%= render :partial =&gt; &quot;browser_detect_start&quot; %&amp;gt;&lt;br /&gt;&amp;lt;%= @content_for_layout %&amp;gt;&lt;br /&gt;&amp;lt;%= render :partial =&gt; &quot;browser_detect_end&quot; %&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;br /&gt;Here&#39;s a simple example of what this enables.  The advantage of this over a conditionally included file is it keeps everything about the login box isolated to one place.  You don&#39;t need to worry about openning up a separate file to make your IE fixes.  &lt;i&gt;We do use iefix specific CSS for our site, but only for very large features like menus&lt;/i&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;#login {&lt;br /&gt;   padding:0px;&lt;br /&gt;}&lt;br /&gt;.ie6 #login {&lt;br /&gt;   padding: 2px;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;</description><link>http://revolutiononrails.blogspot.com/2007/05/css-browser-selector.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-8189579672735875756</guid><pubDate>Wed, 02 May 2007 13:36:00 +0000</pubDate><atom:updated>2007-05-02T07:38:36.545-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">layouts</category><category domain="http://www.blogger.com/atom/ns#">partials</category><category domain="http://www.blogger.com/atom/ns#">plugem</category><category domain="http://www.blogger.com/atom/ns#">rhtml</category><category domain="http://www.blogger.com/atom/ns#">views</category><title>Plugems - Why views in plugems?</title><description>&lt;p&gt;&lt;br /&gt;When we started to develop Plugems we had multiple applications that all shared a similar look and feel.  One concept that emerged recently for me was that layouts can act like objects.  In our suite of applications, we have a base layout that each application can derive from to satisfy it&#39;s unique set of presentation requirements.   For example our UI plugem has the following:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; ui/views/layouts/default.rhtml&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Using a little magic from &lt;a title=&quot;Write your own&quot; href=&quot;http://fora.pragprog.com/rails-recipes/write-your-own/post/144&quot;&gt;fora.pragprog&lt;/a&gt;  we can extend our default layout writing the following:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;% inside_layout &#39;default&#39; do -%&gt;&lt;br /&gt;     &lt;%= @content_for_layout %&gt;&lt;br /&gt;  &lt;% end -%&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;As well as with layouts, there are also smaller blocks of UI that make up a page that can be shared.  I&#39;ve always thought of these as widgets, which in many cases can be defined as a set of partials and helpers.  An application may place a widget on a view, feeding it the data needed to bring it to life. This is different from components because there is no controller logic. Really the presentation side of a widget can be expressed by a set of partials, Javascript, CSS and a healthy dose of ruby [e.g. helpers].  In this way partials are the basic building block on which many UI components can be built.  By themselves they are incomplete, but within the context of an application they are alive...&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt; Plugems enables you to share common UI widgets across multiple applications. Common assets (css, js, images) can live in a plugem, but be shared across applications at deployment time. I hope to post more in depth on this topic in near future.&lt;br /&gt;&lt;/p&gt;</description><link>http://revolutiononrails.blogspot.com/2007/05/plugems-why-views-in-plugems.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-38601396.post-6413631365042659618</guid><pubDate>Sat, 28 Apr 2007 13:49:00 +0000</pubDate><atom:updated>2007-04-30T13:44:24.500-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">captcha</category><category domain="http://www.blogger.com/atom/ns#">fun</category><title>Captcha on Rails</title><description>&lt;p&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGuQuIuvYKY1shymKyRhfxc5OlFeNsfa34SmCFtO8BeWSm2yma2QNGoMFSZebrLJPcfAu2-bQSR7OkDCMgud-R8gFR_LLgi0FCdlSBCvEQmBpJJfBMI4yAJlCZW3uRi-_SHZLS/s320/lotr.jog&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5058510906857158722&quot; border=&quot;0&quot; /&gt;Thinking about how &lt;a href=&quot;http://en.wikipedia.org/wiki/Captcha&quot;&gt;Captcha&lt;/a&gt; handling could be implemented in Rails is a good mental exercise. Leaving aside the issue with entry barriers it creates for some people, and possible underlying technology implementations (like &lt;a href=&quot;http://pics.binary.ru/full/2005_03_04_registration.gif&quot;&gt;not-so-simple mathematical questions&lt;/a&gt;), let&#39;s formulate typical Captcha assumptions and requirements for a medium-sized Rails application:&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Image based&lt;/li&gt;&lt;li&gt;Image/code combination could not be reused&lt;/li&gt;&lt;li&gt;On an unsuccessful attempt, a new Captcha image is displayed&lt;/li&gt;&lt;li&gt;Potentially multiple Rails application servers&lt;/li&gt;&lt;li&gt;The attacker potentially knows the details on how you implemented Captcha&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;Let&#39;s pretend that we know how to generate a perfect Captcha image based on a supplied code string. All we need now is to meet the rest of the requirements.&lt;br /&gt;&lt;br /&gt;Image/code combination could not be reused, means a need to prevent a human from entering the correct code, capturing a post sent to a server, and then replaying it many times via a robot.&lt;br /&gt;&lt;br /&gt;Another point to remember is that a form with a link is generated on the first browser request, an image is retrieved with another request, and the Captcha validation goes with the third one. Potentially all three might arrive to different application servers.&lt;br /&gt;&lt;br /&gt;Now, if you like challenges, try to think about possible solutions. The rest of this post talks about a few I have come up with by myself, though some might have been influenced by brainstorming sessions with the Revolution On Rails team.&lt;br /&gt;&lt;br /&gt;In many of the solutions, a shared storage is used to overcome the multiple servers limitation. It could be a DB (ActiveRecord), memcached (Session), or some other solution. There is a clean up issue for cases when users abandon a Captcha form without entering a code. For some storage types (like memcached) it is taken care of by the engine itself, while for others a periodic cleaning job is required.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Unbreakable&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Image/Code Generation on Request #1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #1&lt;/span&gt;. The application generates a code and an image and puts them into a Storage. A unique Captcha id (for example a captcha record id from ActiveRecord) is used in an image URL as well as in a hidden form field.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #2&lt;/span&gt;. Based on the Captcha id, the image is retrieved and deleted from the Storage. The image is sent to a browser via send_file.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #3&lt;/span&gt;. The entered code is compared with code retrieved from the Storage, based on the captcha id. Regardless of the result, the record is deleted from the Storage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Code Generation on Request #1, Image Generation on Request #2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #1&lt;/span&gt;. The application generates a code and puts it into Storage. A unique captcha id is used in an image URL as well as in a hidden form field.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #2&lt;/span&gt;. Based on the Captcha id, the code is retrieved from Storage and used for generation of an image. The image is being  displayed via send_file.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #3&lt;/span&gt;. The entered code is compared with one retrieved from the Storage based on the Captcha id. Regardless of the result, the record is deleted from the Storage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Image/Code Generation on Request #2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #1&lt;/span&gt;. A unique captcha id is generated and is used in an image URL as well as in a hidden form field.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #2&lt;/span&gt;. The application generates a code and puts it into a Storage. An image, based on the code, is generated and is being showed via send_file.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #3&lt;/span&gt;. The entered code is compared with one retrieved from the Storage based on the captcha id. Regardless of the result, the record is deleted from the Storage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Image/Code Generation on Request #1 with Code Hash &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #1&lt;/span&gt;. The application generates a code and puts a hash of it in a hidden field form. An image is generated and is put into a Storage. A unique Captcha id is used in an image URL as well as in a hidden form field.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #2&lt;/span&gt;. Based on the Captcha id, the image is retrieved and deleted from the Storage. The image is sent to a browser via send_file.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #3&lt;/span&gt;. The entered code is compared with the hashed one. Regardless of the result, the record is deleted from the Storage.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Potentially Breakable&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Some of the potentially breakable solutions are perfectly acceptable for a practical usage since the risk could be very low while benefits of doing image generation offline or having no storage involved could be significant.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Pre-Generated Code/Image&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are several scenarios with code/image pairs pre-generated off-line but none that can sustain an attack based on calculation of an image hash, noting the correct code, and calling the form till the same image comes again. The volume of images and frequency of their regeneration defines the level of risk.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;No Storage&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It is probebly not possible to come up with a generic solution involving no storage of any kind, while meeting all the requirements. There are some special cases though, with very low security risk. For example, a two-step login process with a standard login screen presented first, and the captcha next:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #1&lt;/span&gt;: The login form is sent.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #2&lt;/span&gt;: The application generates a code, encrypts it is with login name and password, and puts the encrypted string in a hidden field form. The image url generates using an encrypted code with some salt (timestamp.)&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #3&lt;/span&gt;. The code is retrieved from the requested url. An image based on the decrypted code is generated, and is displayed via send_file.&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Request #4&lt;/span&gt;. The entered code is compared with the decrypted and the account is then verified if the correct code was entered.&lt;br /&gt;&lt;br /&gt;The obvious attack vector is to crack/steal the key, though in practice it is a well-understood problem to address.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:130%;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Conclusion&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Most likely there are papers on Captcha describing all the aforementioned solutions and many more, so this post could be seen as &lt;a href=&quot;http://worsethanfailure.com/Articles/I_Think_I_0x27_ll_Call_Them__0x26_quot_0x3b_Transactions_0x26_quot_0x3b_.aspx&quot;&gt;reinventing the wheel&lt;/a&gt;. Still, it was fun thinking about them. It would be great to hear about a perfect generic no-storage solution, feel free to share if you have an idea.</description><link>http://revolutiononrails.blogspot.com/2007/04/pedo-mellon-minno-or-captcha-on-rails.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGuQuIuvYKY1shymKyRhfxc5OlFeNsfa34SmCFtO8BeWSm2yma2QNGoMFSZebrLJPcfAu2-bQSR7OkDCMgud-R8gFR_LLgi0FCdlSBCvEQmBpJJfBMI4yAJlCZW3uRi-_SHZLS/s72-c/lotr.jog" height="72" width="72"/><thr:total>5</thr:total></item></channel></rss>