<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Srinathonrails's Blog</title>
	<atom:link href="http://srinathonrails.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://srinathonrails.wordpress.com</link>
	<description>Lessons learned from my exploration of Ruby on Rails  !!!</description>
	<lastBuildDate>Tue, 10 Jan 2012 03:12:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='srinathonrails.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Srinathonrails's Blog</title>
		<link>http://srinathonrails.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://srinathonrails.wordpress.com/osd.xml" title="Srinathonrails&#039;s Blog" />
	<atom:link rel='hub' href='http://srinathonrails.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Jumble elements in an Array</title>
		<link>http://srinathonrails.wordpress.com/2010/12/21/jumble-elements-in-an-array/</link>
		<comments>http://srinathonrails.wordpress.com/2010/12/21/jumble-elements-in-an-array/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 17:49:37 +0000</pubDate>
		<dc:creator>Srinath A</dc:creator>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[ruby array jumble]]></category>

		<guid isPermaLink="false">http://srinathonrails.wordpress.com/?p=57</guid>
		<description><![CDATA[After a long time i was stuck on a simple issue . Hope this solution would help for some one searching on google or ruby-api for instant . Here is the solution for jumbling array elements Non-optimal Ruby 1.8.6 code : array.sort_by { rand } Ruby 1.8.7+ have an optimised version built in: array.shuffle Enjoy<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=57&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a long time i was stuck on a simple issue . Hope this solution would help for  some one searching on google or ruby-api for instant .</p>
<p>Here is the solution for jumbling array elements </p>
<p>Non-optimal Ruby 1.8.6 code :<br />
array.sort_by { rand }</p>
<p>Ruby 1.8.7+ have an optimised version built in:<br />
array.shuffle</p>
<p>Enjoy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/srinathonrails.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/srinathonrails.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/srinathonrails.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/srinathonrails.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/srinathonrails.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/srinathonrails.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/srinathonrails.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/srinathonrails.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=57&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://srinathonrails.wordpress.com/2010/12/21/jumble-elements-in-an-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc578efe3bb69e763ec7695d675c06a?s=96&#38;d=" medium="image">
			<media:title type="html">srinathonrails</media:title>
		</media:content>
	</item>
		<item>
		<title>Subdomains in Rails Applications</title>
		<link>http://srinathonrails.wordpress.com/2009/03/03/subdomains-in-rails-applications/</link>
		<comments>http://srinathonrails.wordpress.com/2009/03/03/subdomains-in-rails-applications/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 13:49:43 +0000</pubDate>
		<dc:creator>Srinath A</dc:creator>
				<category><![CDATA[Routing]]></category>
		<category><![CDATA[subdomains]]></category>

		<guid isPermaLink="false">http://srinathonrails.wordpress.com/?p=30</guid>
		<description><![CDATA[Defining Subdomains for Local Development When you begin developing an application using subdomains, you need to move beyond using http://locahost:3000 as we need to be able to develop and test with subdomains. You can open up your /etc/hosts (within a Unix-based O/S) file and add the following. 127.0.0.1 localhost 127.0.0.1 lifestyle.dev 127.0.0.1 life2go.lifestyle.dev 127.0.0.1 vitalzeu.lifestyle.dev [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=30&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Defining Subdomains for Local Development</strong></p>
<p>When you begin developing an application using subdomains, you need to move beyond using <a href="http://locahost:3000">http://locahost:3000</a> as we need to be able to develop and test with subdomains. You can open up your <code>/etc/hosts</code> (within a Unix-based O/S) file and add the following.</p>
<pre><code>127.0.0.1 localhost
127.0.0.1 lifestyle.dev
127.0.0.1 life2go.lifestyle.dev
127.0.0.1 vitalzeu.lifestyle.dev

This will let you make request to <a href="http://lifestyle.dev:3000">http://lifestyle.dev:3000</a> and <a href="http://life2go.lifestyle.dev:3000">http://life2go.lifestyle.dev:3000</a>
It's important to remember that the subdomain must be specified here to work for local requests.
Unfortunately hosts file dont support wild cards(*).

<strong><span style="color:#003300;"><span style="color:#800000;">Detecting Subdomains in Rails</span>

</span></strong>In the application.rb file add this line to find subdomains
@subdomains = request.subdomains.first

The subdomains method isn't particularly smart, all it does is splitting on.and returning all but the
last two parts. So to get it to work in development then you will need to have the same number
of parts to your domain as you will in production.
So if you'd have <a href="http://life2go.lifestyle.com">life2go.lifestyle.com</a> in production then you will need to have three part domain
names in development too, so something like <a href="http://life2go.lifestyle.dev">life2go.lifestyle.dev</a> mapped to your 127.0.0.1 address.
<a href="http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M000359&amp;name=subdomains">
Take a look at the doco</a> for more information.

<span style="color:#0000ff;"><strong>The request.subdomains.first will work both in production and development environments.</strong></span>
</code></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/srinathonrails.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/srinathonrails.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/srinathonrails.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/srinathonrails.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/srinathonrails.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/srinathonrails.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/srinathonrails.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/srinathonrails.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=30&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://srinathonrails.wordpress.com/2009/03/03/subdomains-in-rails-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc578efe3bb69e763ec7695d675c06a?s=96&#38;d=" medium="image">
			<media:title type="html">srinathonrails</media:title>
		</media:content>
	</item>
		<item>
		<title>Migrating Stored Procedures in RoR</title>
		<link>http://srinathonrails.wordpress.com/2009/01/30/migrating-stored-procedures-in-ror/</link>
		<comments>http://srinathonrails.wordpress.com/2009/01/30/migrating-stored-procedures-in-ror/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 05:12:33 +0000</pubDate>
		<dc:creator>Srinath A</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://srinathonrails.wordpress.com/?p=24</guid>
		<description><![CDATA[This similar article may be found on the internet,  but i guess this article will be helpful for newbie&#8217;s. Migrations are a convenient way to alter your database in a structured and organised manner. Here we are going to see how to create stored procedures with rake db:migrate First create a new migration file in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=24&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This similar article may be found on the internet,  but i guess this article will be helpful for newbie&#8217;s.</p>
<p>Migrations are a convenient way to alter your database in a structured and organised manner.</p>
<p>Here we are going to see how to create stored procedures with <strong>rake db:migrate</strong></p>
<p>First create a new migration file in your db/migrate folder using</p>
<p><code><strong>ruby script/generate migration stored_procedures. </strong>This will create the file db/migrate/001_stored_procedures.</code></p>
<h3>Edit the code to tell it what to do.</h3>
<p>The method <code>self.up</code> is used when migrating to a new version, <code>self.down</code> is used to roll back any changes if needed.  The class name needs to be the same as the migration name (i.e. <code>db/migrate/</code><code>001_stored_procedures</code> needs a class name of @<code>StoredProcedures</code>@).</p>
<p>Let us migrate a stored procedure called items with a basic sql code :</p>
<p>The migration file now looks like this :</p>
<pre><code>class StoredProcedures &lt; ActiveRecord::Migration
  def self.up
    execute &lt;&lt;-__EOI
      CREATE DEFINER=`root`@`localhost` PROCEDURE `items`(IN l_item INT,IN userid INT,OUT l_itemid INT,OUT l_item_name VARCHAR)
      BEGIN SELECT itemid,item_name,held_by,id INTO l_itemid,userid,id FROM users_items WHERE itemid=l_item AND held_by=userid;
      END
    __EOI
  end
  def self.down
    execute "DROP PROCEDURE IF EXISTS `items`"
  end
end

And now the cool part is just run rake db:migrate, Rails will create all the migration files in your database and also creates Stored procedures.</code></pre>
<p><span class="hover_target"><strong></strong></span></p>
<p><span class="hover_target"><strong><br />
</strong></span></p>
<p><span class="hover_target"><strong><br />
</strong></span></p>
<p><strong><br />
</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/srinathonrails.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/srinathonrails.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/srinathonrails.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/srinathonrails.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/srinathonrails.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/srinathonrails.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/srinathonrails.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/srinathonrails.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=24&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://srinathonrails.wordpress.com/2009/01/30/migrating-stored-procedures-in-ror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc578efe3bb69e763ec7695d675c06a?s=96&#38;d=" medium="image">
			<media:title type="html">srinathonrails</media:title>
		</media:content>
	</item>
		<item>
		<title>Redirecting/Using rails application for different Domains</title>
		<link>http://srinathonrails.wordpress.com/2008/12/12/redirectingusing-rails-application-to-different-urls/</link>
		<comments>http://srinathonrails.wordpress.com/2008/12/12/redirectingusing-rails-application-to-different-urls/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 10:25:54 +0000</pubDate>
		<dc:creator>Srinath A</dc:creator>
				<category><![CDATA[Routing]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[routes]]></category>

		<guid isPermaLink="false">http://srinathonrails.wordpress.com/?p=11</guid>
		<description><![CDATA[I was Wondering how to use my Rails application to redirect to two URLs .My application should be used on two domains with one server and one database at my back end with single application. I faced this scenario when i was working for an onsite project. going into details&#8230; when we hit on domain1 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=11&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was Wondering how to use my Rails application to redirect to two URLs .My application should be used on two domains with one server and one database at my back end with single application. I faced this scenario when i was working for an onsite project.</p>
<p>going into details&#8230;</p>
<p>when we hit on domain1 say<a href="http://domain1.com"> http://www.domain1.com</a> the app should redirect to <strong>controller =&gt; :home, action =&gt; :home</strong> an when we hit on domain2 say <a href="http://domain2.com">http://www.domain2.com</a> the app should redirect to <strong>controller =&gt; :account, :action =&gt; :login</strong>. This is the actual scenario that we were looking</p>
<p>The major part of the code handles with <span style="color:#800000;">Routes.rb and Environment.rb.</span></p>
<p>First write a method in application.rb/application_helper.rb to deferentiate any css/images/links visible on that domains</p>
<p>let us say in application.rb the code looks like</p>
<p><span style="color:#800080;"># check Whois Domain Name<br />
# Domain name will be domain1.com or domain2.com based on the request</span></p>
<p><span style="color:#800080;">def check_domain?</span></p>
<p><span style="color:#800080;">if request.domain == &#8220;domain1.com&#8221;</span></p>
<p><span style="color:#800080;">login_required</span></p>
<p><span style="color:#800080;">elsif request.domain ==&#8221;domain2.com&#8221;</span></p>
<p><span style="color:#800080;"># login not required</span></p>
<p><span style="color:#800080;">end</span></p>
<p><span style="color:#800080;">and finally add the code in your application to differntiate URls</span></p>
<pre class="textmate-source">
<pre class="sunburst"><span style="color:#800080;"><span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># in config/routes.rb</span>
map<span class="meta meta_function-call meta_function-call_method meta_function-call_method_without-arguments meta_function-call_method_without-arguments_ruby">.<span class="entity entity_name entity_name_function entity_name_function_ruby">connect</span></span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby">''</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:controller</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'domain_tests'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:action</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'domain1'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:conditions</span> =&gt; {<span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:domain</span> =&gt; <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"domain1"</span>}
map<span class="meta meta_function-call meta_function-call_method meta_function-call_method_without-arguments meta_function-call_method_without-arguments_ruby">.<span class="entity entity_name entity_name_function entity_name_function_ruby">connect</span></span> <span class="string string_quoted string_quoted_single string_quoted_single_ruby">''</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:controller</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'domain_tests'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:action</span> =&gt; <span class="string string_quoted string_quoted_single string_quoted_single_ruby">'domain2'</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:conditions</span> =&gt; {<span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:domain</span> =&gt; <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"domain2"</span>}

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># in config/environment.rb after the initialize section</span>
<span class="meta meta_module meta_module_ruby"><span class="keyword keyword_control keyword_control_module keyword_control_module_ruby">module</span> <span class="entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby">ActionController</span></span>
<span class="meta meta_module meta_module_ruby">  <span class="keyword keyword_control keyword_control_module keyword_control_module_ruby">module</span> <span class="entity entity_name entity_name_type entity_name_type_module entity_name_type_module_ruby">Routing</span></span>
<span class="meta meta_class meta_class_ruby">    <span class="keyword keyword_control keyword_control_class keyword_control_class_ruby">class</span> <span class="entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby">RouteSet</span></span>
      <span class="meta meta_function meta_function_method meta_function_method_with-arguments meta_function_method_with-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">extract_request_environment</span>(<span class="variable variable_parameter variable_parameter_function variable_parameter_function_ruby">request</span>)</span>
        {<span class="meta meta_syntax meta_syntax_ruby meta_syntax_ruby_start-block"> </span><span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:method</span> =&gt; request<span class="meta meta_function-call meta_function-call_method meta_function-call_method_without-arguments meta_function-call_method_without-arguments_ruby">.<span class="entity entity_name entity_name_function entity_name_function_ruby">method</span></span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:domain</span> =&gt; request<span class="meta meta_function-call meta_function-call_method meta_function-call_method_without-arguments meta_function-call_method_without-arguments_ruby">.<span class="entity entity_name entity_name_function entity_name_function_ruby">domain</span></span><span class="meta meta_function-call meta_function-call_method meta_function-call_method_with-arguments meta_function-call_method_with-arguments_ruby">.<span class="entity entity_name entity_name_function entity_name_function_ruby">split</span></span>(<span class="string string_quoted string_quoted_single string_quoted_single_ruby">'.'</span>)<span class="meta meta_function-call meta_function-call_method meta_function-call_method_without-arguments meta_function-call_method_without-arguments_ruby">.<span class="entity entity_name entity_name_function entity_name_function_ruby">first</span></span> }
      <span class="keyword keyword_control keyword_control_ruby">end</span>
    <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="meta meta_class meta_class_ruby">    <span class="keyword keyword_control keyword_control_class keyword_control_class_ruby">class</span> <span class="entity entity_name entity_name_type entity_name_type_class entity_name_type_class_ruby">Route</span></span>
      <span class="keyword keyword_control keyword_control_pseudo-method keyword_control_pseudo-method_ruby">alias_method</span> <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby"> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ld_recognition_conditions</span>, <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:recognition_conditions</span>
      <span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">recognition_conditions</span></span>
        result <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_ruby">=</span> old_recognition_conditions
        result <span class="keyword keyword_operator keyword_operator_assignment keyword_operator_assignment_augmented keyword_operator_assignment_augmented_ruby">&lt;&lt;</span> <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"conditions[:hostname] === env[:hostname]"</span> <span class="keyword keyword_control keyword_control_ruby">if</span> conditions[<span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:hostname</span>]
        result
      <span class="keyword keyword_control keyword_control_ruby">end</span>
    <span class="keyword keyword_control keyword_control_ruby">end</span>
  <span class="keyword keyword_control keyword_control_ruby">end</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># courtesy of http://www.smallroomsoftware.com/articles/2007/2/10/rails-routing-based-on-hostname</span>

<span class="comment comment_line comment_line_number-sign comment_line_number-sign_ruby"># in app/domain_tests_controller.rb</span>
<span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">domain1</span></span>
  <span class="support support_function support_function_actionpack support_function_actionpack_rails">render</span> <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:text</span> =&gt; <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"you've hit domain one"</span>
<span class="keyword keyword_control keyword_control_ruby">end</span>

<span class="meta meta_function meta_function_method meta_function_method_without-arguments meta_function_method_without-arguments_ruby"><span class="keyword keyword_control keyword_control_def keyword_control_def_ruby">def</span> <span class="entity entity_name entity_name_function entity_name_function_ruby">domain2</span></span>
  <span class="support support_function support_function_actionpack support_function_actionpack_rails">render</span> <span class="constant constant_other constant_other_symbol constant_other_symbol_ruby">:text</span> =&gt; <span class="string string_quoted string_quoted_double string_quoted_double_ruby">"you've hit domain two"</span>
</span><span class="keyword keyword_control keyword_control_ruby"><span style="color:#800080;">end

</span>Finally we are done and this works in Production pretty good !!!
Test it in your app's and get me a feedback ..ciao
</span></pre>
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/srinathonrails.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/srinathonrails.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/srinathonrails.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/srinathonrails.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/srinathonrails.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/srinathonrails.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/srinathonrails.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/srinathonrails.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=11&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://srinathonrails.wordpress.com/2008/12/12/redirectingusing-rails-application-to-different-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc578efe3bb69e763ec7695d675c06a?s=96&#38;d=" medium="image">
			<media:title type="html">srinathonrails</media:title>
		</media:content>
	</item>
		<item>
		<title>Optimising RoR application for Amazon EBS</title>
		<link>http://srinathonrails.wordpress.com/2008/11/28/optimising-ror-application-for-amazon-ebs/</link>
		<comments>http://srinathonrails.wordpress.com/2008/11/28/optimising-ror-application-for-amazon-ebs/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 14:42:42 +0000</pubDate>
		<dc:creator>Srinath A</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[optimising]]></category>

		<guid isPermaLink="false">http://srinathonrails.wordpress.com/?p=8</guid>
		<description><![CDATA[Amazon has a great feature called EBS which enables to have data persistence in the event of an instance failure. We have configured mysql to use the EBS for datafiles. Details for this can be found here: http://docs.google.com/Doc?id=dcn2ckbh_21gznbbjhr Though a great feature, EBS has a couple of operational limitations. 1. It has a cryptic billing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=8&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Amazon has a great feature called EBS which enables to have data persistence in the event of an instance failure.<br />
We have configured mysql to use the EBS for datafiles. Details for this can be found here: <a href="http://docs.google.com/Doc?id=dcn2ckbh_21gznbbjhr">http://docs.google.com/Doc?id=dcn2ckbh_21gznbbjhr</a></p>
<p>Though a great feature, EBS has a couple of operational limitations.<br />
1. It has a cryptic billing structure which bills based on (capacity + usage). Now most of us can&#8217;t really predict the usage of disk and risk overshooting this.<br />
2. EBS will be slower that locally mounted storage.</p>
<p>To overcome these issues, in our RoR application, we decided make some changes.</p>
<p>We decided to upload all user data to TWO locations &#8211; 1st location is the usual &#8220;RoR-app-home/public/&#8221; directory. This directory is in the local storage of the instance.<br />
The 2nd location is the EBS (/dev/sdh) mounted on /mnt/data-store of the instance. Within data-store, we created a few directories for storing various types of user data.<br />
1. During upload, the data is copied to both locations. i.e. We write to both local and EBS.<br />
2. During read &#8211; we read it from local directory of EC2. This local reads ensures that EBS is not hit with multiple read requests and our EBS costs are low. There is alo the speed benefit of reading from local storage as opposed to reading from EBS (Amazon AWs developers can correct me on the speed issue.)</p>
<p>Here is the sampe code where we are uploading a video and a thumbnail associated with the video: <span style="background-color:#ffff00;">Keep and eye out for &#8220;video.rewind&#8221;.</span></p>
<p>Add in app/model/video.rb <span style="background-color:#ffff00;">(for our application &#8211; you will have adapt for you app.)</span></p>
<p>VIDEO_UPLOAD_PATH = &#8220;public/video_player/videos/&#8221;<br />
THUMBNAIL_UPLOAD_PATH = &#8220;public/video_player/thumbnail/&#8221;</p>
<p>#Manage the path depending on OS<br />
#Hard disk usage Optimisation for AWS.<br />
#Replicate videos, images, into AWS local hard disk.</p>
<p><strong>VIDEO_UPLOAD_PATH_FOR_AWS = &#8220;/mnt/data-store/app-data/videos/&#8221;</strong><br />
<strong>THUMBNAIL_UPLOAD_PATH_FOR_AWS = &#8220;/mnt/data-store/app-data/thumbnails/&#8221;</strong></p>
<p># create and upload video , thumbail<br />
<strong>def self.create_video</strong><br />
if valid_video?(video) &amp;&amp; valid_thumbnail?(thumbnail)<br />
video_filename = sanitize_attachment_name(video)<br />
thumbnail_filename = sanitize_attachment_name(thumbnail)<br />
@video = self.new do |video|<br />
video.video_name = video_filename<br />
video.thumbnail_name = thumbnail_filename<br />
end<br />
self.upload_video(video, video_filename, @video.id) &amp;&amp; self.upload_thumbnail(thumbnail, thumbnail_filename, @video.id) if @video.save<br />
end<br />
<strong>end</strong></p>
<p><strong>def self.upload_video(video, video_filename, video_id)</strong><br />
video_path = VIDEO_UPLOAD_PATH + &#8220;#{ video_id}_&#8221; + video_filename<br />
File.open(video_path, &#8220;wb&#8221;) { |f| f.write(video.read) }<br />
# code to manage video upload file to EBS<br />
video.rewind<br />
video_path_for_aws = VIDEO_UPLOAD_PATH_FOR_AWS + &#8220;#{ video_id}_&#8221; + video_filename<br />
File.open( video_path_for_aws, &#8220;wb&#8221;) { |f| f.write(video.read) }<br />
<strong>end</strong></p>
<p><strong>def self.upload_thumbnail(thumbnail, thumbnail_filename, video_id)</strong><br />
thumbnail_path = THUMBNAIL_UPLOAD_PATH + &#8220;#{ video_id}_&#8221; + thumbnail_filename<br />
File.open(thumbnail_path, &#8220;wb&#8221;) { |f| f.write(thumbnail.read) }<br />
# code to manage thumbnail image upload file to EBS<br />
thumbnail.rewind<br />
thumbnail_path_for_aws = THUMBNAIL_UPLOAD_PATH_FOR_AWS + &#8220;#{ video_id}_&#8221; + thumbnail_filename<br />
File.open(thumbnail_path_for_aws, &#8220;wb&#8221;) { |f| f.write(thumbnail.read) }<br />
<strong>end</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/srinathonrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/srinathonrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/srinathonrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/srinathonrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/srinathonrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/srinathonrails.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/srinathonrails.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/srinathonrails.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=8&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://srinathonrails.wordpress.com/2008/11/28/optimising-ror-application-for-amazon-ebs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc578efe3bb69e763ec7695d675c06a?s=96&#38;d=" medium="image">
			<media:title type="html">srinathonrails</media:title>
		</media:content>
	</item>
		<item>
		<title>Auto complete issue with non-Mozilla browsers</title>
		<link>http://srinathonrails.wordpress.com/2008/11/28/auto-complete-issue-with-non-mozilla-browsers/</link>
		<comments>http://srinathonrails.wordpress.com/2008/11/28/auto-complete-issue-with-non-mozilla-browsers/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 14:27:43 +0000</pubDate>
		<dc:creator>Srinath A</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[autocomplete]]></category>

		<guid isPermaLink="false">http://srinathonrails.wordpress.com/?p=4</guid>
		<description><![CDATA[Playing with auto complete in Firefox is fun all the time , but this is not going to be same in Others Browsers(IE &#38; Safari), after Googling for many days i came up with a pleasant solution. Rails2.0: auto_complete is now a plugin (it’s not in the core anymore), you will install it before using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=4&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Playing with auto complete in Firefox is fun all the time , but this is not going to be same in Others Browsers(IE &amp; Safari),<br />
after Googling for many days i came up with a pleasant solution.</p>
<p>Rails2.0: auto_complete is now a plugin (it’s not in the core anymore), you will install it before using it:<br />
script/plugin install auto_complete</p>
<p>Somewhere in your views you’ll want code somewhat like the following.<br />
&lt;%= text_field_with_auto_complete :article, :contains, { :size =&gt; 15 }, :skip_style =&gt; true %&gt;</p>
<p>I specified a size for the text area with the :size =&gt; 15 values in the hash. I also included :skip_style =&gt; true which keeps the helper from automatically inlining CSS styles into the page.</p>
<p>and now the major issue i faced with IE and Safari browsers are :<br />
<span style="font-weight:bold;">Q. Up, Down arrow keys are not working for auto complete in non-mozilla browsers when drop down list appears</span><br />
<span style="font-style:italic;">The solution is ..</span><br />
<span>This is due to a bug in Scriptaculous. At the time of writing you will need to apply the following patch that will fix it:</span><br />
in controls.js around line 86 you will observe these lines<br />
Element.hide(this.update);<br />
Event.observe(this.element, &#8216;blur&#8217;, this.onBlur.bindAsEventListener(this));<br />
Event.observe(this.element, &#8216;keydown&#8217;, this.onKeyPress.bindAsEventListener(this));<br />
},</p>
<p>and now you modify above lines with the following code of lines :</p>
<p>Element.hide(this.update);<br />
Event.observe(this.element, &#8216;blur&#8217;, this.onBlur.bindAsEventListener(this));<br />
Event.observe(this.element, &#8216;keypress&#8217;, this.onKeyPress.bindAsEventListener(this));<br />
// Observe keydown for non-Mozilla browsers per http://dev.rubyonrails.org/ticket/10126<br />
if (Prototype.Browser.Gecko) {<br />
Event.observe(this.element, &#8216;keypress&#8217;, this.onKeyPress.bindAsEventListener(this));<br />
} else {<br />
Event.observe(this.element, &#8216;keydown&#8217;, this.onKeyPress.bindAsEventListener(this));<br />
}<br />
},<br />
and restart the server ,now the arrow keys will work in both IE and Safari browsers.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/srinathonrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/srinathonrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/srinathonrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/srinathonrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/srinathonrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/srinathonrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/srinathonrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/srinathonrails.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=srinathonrails.wordpress.com&amp;blog=5639634&amp;post=4&amp;subd=srinathonrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://srinathonrails.wordpress.com/2008/11/28/auto-complete-issue-with-non-mozilla-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bcc578efe3bb69e763ec7695d675c06a?s=96&#38;d=" medium="image">
			<media:title type="html">srinathonrails</media:title>
		</media:content>
	</item>
	</channel>
</rss>
