<?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/"
	>

<channel>
	<title>Ai ♥ Ruby on Rails</title>
	<atom:link href="http://railsblog.ainakatani.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://railsblog.ainakatani.com</link>
	<description>Let&#039;s build a powerful, dynamic website!</description>
	<lastBuildDate>Mon, 13 Jun 2011 20:55:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A New Server =&gt; A New Start</title>
		<link>http://railsblog.ainakatani.com/?p=293</link>
		<comments>http://railsblog.ainakatani.com/?p=293#comments</comments>
		<pubDate>Mon, 13 Jun 2011 20:35:56 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Ai's Rails Projects]]></category>
		<category><![CDATA[Deploying Apps]]></category>
		<category><![CDATA[Heroku]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[HostMonster]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=293</guid>
		<description><![CDATA[
I recently moved both of my Rails applications to Heroku.
I used to use Hostmonster (and this blog still runs on Hostmonster), but they are not specialized in Rails, so deployment and maintenance became just too complicated. They could not give the kind of support I wanted. Also, the apps were so slow there.
Heroku made my [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>I recently moved both of my Rails applications to <a title="Heroku" href="http://www.heroku.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.heroku.com?referer=');">Heroku</a>.</p>
<p>I used to use Hostmonster (and this blog still runs on Hostmonster), but they are not specialized in Rails, so deployment and maintenance became just too complicated. They could not give the kind of support I wanted. Also, the apps were so slow there.</p>
<p>Heroku made my work so much easier. I admire the engineers who created it.</p>
<p>For those who want to learn Ruby on Rails and didn&#8217;t know about Heroku, I would say that this is the ONLY way I recommend for you to deploy your rails app.</p>
<p>It&#8217;s also free if you don&#8217;t need a gigantic space or special features.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=293</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing a locale as a hidden field in a form</title>
		<link>http://railsblog.ainakatani.com/?p=287</link>
		<comments>http://railsblog.ainakatani.com/?p=287#comments</comments>
		<pubDate>Wed, 28 Jul 2010 23:05:41 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Localization and Foreign Languages]]></category>
		<category><![CDATA[default locale]]></category>
		<category><![CDATA[hidden field]]></category>
		<category><![CDATA[hidden parameter]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Internationalization]]></category>
		<category><![CDATA[locale]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=287</guid>
		<description><![CDATA[I explained in this post how to automatically append locale as a parameter at end of every URL throughout the site. However, when you have a form like this, you have to pass a locale using a hidden field in the form.


&#60;% form_tag &#8216;&#8230;&#8216;, :method =&#62; &#8216;get&#8217; do %&#62;
&#8230;..
some input text fields/text box
&#8230;..
&#60;% if !params[:locale].nil? [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">I explained <a title="my past post" href="?p=278" target="_blank">in this post</a> how to automatically append locale as a parameter at end of every URL throughout the site. However, when you have a form like this, you have to pass a locale using a hidden field in the form.</div>
<div></div>
<div>
<div style="padding-left: 30px;">&lt;% form_tag &#8216;<em>&#8230;</em>&#8216;, :method =&gt; &#8216;get&#8217; do %&gt;</div>
<div style="padding-left: 60px;">&#8230;..</div>
<div style="padding-left: 60px;">some input text fields/text box</div>
<div style="padding-left: 60px;">&#8230;..</div>
<div style="padding-left: 60px;"><strong><span style="color: #ff0000;">&lt;% if !params[:locale].nil? %&gt;</span></strong></div>
<div style="padding-left: 90px;"><strong><span style="color: #ff0000;">&lt;%= hidden_field_tag :locale, params[:locale] %&gt;</span></strong></div>
<div style="padding-left: 60px;"><strong><span style="color: #ff0000;">&lt;% end %&gt;</span></strong></div>
<div style="padding-left: 60px;">&lt;%= submit_tag (&#8230;..) %&gt;</div>
<div style="padding-left: 30px;">&lt;% end %&gt;</div>
<div style="padding-left: 30px;"></div>
</div>
<div>Now, if your locale is not nil (that is, not the default), locale will be appended to the next URL.</div>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=287</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting the Default Locale on I18N</title>
		<link>http://railsblog.ainakatani.com/?p=282</link>
		<comments>http://railsblog.ainakatani.com/?p=282#comments</comments>
		<pubDate>Wed, 28 Jul 2010 22:30:55 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Localization and Foreign Languages]]></category>
		<category><![CDATA[default locale]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Internationalization]]></category>
		<category><![CDATA[locale]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=282</guid>
		<description><![CDATA[Specify the default locale by uncommenting the following two lines in config/environment.rb file:
Rails::Initializer.run do &#124;config&#124;
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
config.i18n.default_locale = :jp
end
]]></description>
			<content:encoded><![CDATA[<p>Specify the default locale by uncommenting the following two lines in <span style="color: #ff0000;"><em>config/environment.rb</em></span> file:</p>
<p>Rails::Initializer.run do |config|</p>
<div id="_mcePaste" style="padding-left: 30px;"># The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.</div>
<div id="_mcePaste" style="padding-left: 30px;"><strong><span style="color: #ff0000;">config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]</span></strong></div>
<div id="_mcePaste" style="padding-left: 30px;"><strong><span style="color: #ff0000;">config.i18n.default_locale = :<span style="font-weight: normal;"><em><span style="color: #000000;">jp</span></em></span></span></strong></div>
<p>end</p>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=282</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I18N and Locales: Appending locale parameter at the end of every URL</title>
		<link>http://railsblog.ainakatani.com/?p=278</link>
		<comments>http://railsblog.ainakatani.com/?p=278#comments</comments>
		<pubDate>Wed, 28 Jul 2010 09:23:56 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Localization and Foreign Languages]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Internationalization]]></category>
		<category><![CDATA[locale]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=278</guid>
		<description><![CDATA[Now, you may be thinking, &#8220;Do I have to care about passing locale as a parameter every time I put a link?&#8221;
For example, like this:
link_to(&#8220;Contact&#8221;, :controller =&#62; &#8220;contacts&#8221;, :action =&#62; &#8220;index&#8221;, :locale =&#62; params[:locale])
This will definitely work, but you don&#8217;t wanna do this throughout your site.
Solution! You just put this piece of code in your [...]]]></description>
			<content:encoded><![CDATA[<p>Now, you may be thinking, &#8220;Do I have to care about passing locale as a parameter every time I put a link?&#8221;</p>
<p>For example, like this:</p>
<p style="padding-left: 30px;">link_to(&#8220;Contact&#8221;, :controller =&gt; &#8220;contacts&#8221;, :action =&gt; &#8220;index&#8221;, <strong>:locale =&gt; params[:locale]</strong>)</p>
<p>This will definitely work, but you don&#8217;t wanna do this throughout your site.</p>
<p>Solution! You just put this piece of code in your <strong><em>app/controllers/application_controller.rb </em></strong></p>
<div id="_mcePaste" style="padding-left: 30px;"><strong><span style="color: #ff0000;">def default_url_options(options={})</span></strong></div>
<div id="_mcePaste" style="padding-left: 60px;"><strong><span style="color: #ff0000;">logger.debug &#8220;default_url_options is passed options: #{options.inspect}\n&#8221;</span></strong></div>
<div id="_mcePaste" style="padding-left: 60px;"><strong><span style="color: #ff0000;">{ :locale =&gt; I18n.locale }</span></strong></div>
<div id="_mcePaste" style="padding-left: 30px;"><strong><span style="color: #ff0000;">end</span></strong></div>
<p>This will automatically append &#8216;<strong><span style="color: #ff0000;">?locale=<span style="font-weight: normal;"><em><span style="color: #000000;">locale&#8217;</span></em></span></span></strong><em><span style="color: #000000;"> </span></em>at the end of every URL when you navigate through the site.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=278</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I18N and Locales</title>
		<link>http://railsblog.ainakatani.com/?p=272</link>
		<comments>http://railsblog.ainakatani.com/?p=272#comments</comments>
		<pubDate>Wed, 28 Jul 2010 09:06:58 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Localization and Foreign Languages]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Internationalization]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=272</guid>
		<description><![CDATA[First, let&#8217;s find a file en.yml under config/locales . That&#8217;s where all of your YAML files will go.
The file should have something like this:
# Sample localization file for English. Add more files in this directory for other locales.
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:

hello: "Hello"
Now create a file jp.yml under config/locales and write this:
jp:
hello: &#8220;ハロー&#8221;
Be careful with [...]]]></description>
			<content:encoded><![CDATA[<p>First, let&#8217;s find a file <strong><em>en</em></strong><strong><em>.yml</em></strong> under <strong><em>config/locales</em></strong> . That&#8217;s where all of your YAML files will go.</p>
<p>The file should have something like this:</p>
<p style="padding-left: 30px;"><code># Sample localization file for English. Add more files in this directory for other locales.<br />
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.<br />
</code></p>
<p style="padding-left: 30px;"><code>en:</code></p>
<p style="padding-left: 60px;"><code><br />
hello: "Hello"</code></p>
<p>Now create a file <strong><em>jp.yml</em></strong> under <strong><em>config/locales </em><span style="font-weight: normal;">and write this:</span></strong></p>
<p style="padding-left: 30px;">jp:</p>
<p style="padding-left: 60px;">hello: &#8220;ハロー&#8221;</p>
<p>Be careful with the indentation (use a Tab key), because it matters.</p>
<p>Now, put the following code somewhere in your top page (view):</p>
<p style="padding-left: 30px;"><strong><span style="color: #ff0000;">&lt;%=t</span> </strong>:hello <strong><span style="color: #ff0000;">%&gt;</span></strong></p>
<p>As you see, instead of typing I18n.t all the time, you can just type t (translate).</p>
<p>Then, try typing this on your address bar: <strong>http://localhost/?locale=jp</strong></p>
<p>Not working? Now add the following to your <em><strong>app/controllers/application_controller.rb </strong><span style="font-style: normal;">file</span></em></p>
<p><em><span style="font-style: normal;"> </span></em></p>
<p><em> </em></p>
<p><em> </em></p>
<p><em> </em></p>
<p><em> </em></p>
<p><em> </em></p>
<p style="padding-left: 30px;">before_filter :set_locale</p>
<p style="padding-left: 30px;">def set_locale</p>
<p style="padding-left: 60px;">I18n.locale = params[:locale]</p>
<p style="padding-left: 30px;">end</p>
<p><span style="font-style: normal;">This should do it!</span></p>
<p>Reference(s):</p>
<ul>
<li><a href="http://guides.rubyonrails.org/i18n.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/guides.rubyonrails.org/i18n.html?referer=');"></a><a href="http://guides.rubyonrails.org/i18n.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/guides.rubyonrails.org/i18n.html?referer=');">Rails Internationalization (I18n) API</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=272</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I18N (Internationalization Gem)</title>
		<link>http://railsblog.ainakatani.com/?p=270</link>
		<comments>http://railsblog.ainakatani.com/?p=270#comments</comments>
		<pubDate>Wed, 28 Jul 2010 08:48:14 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Ai's Rails Projects]]></category>
		<category><![CDATA[Localization and Foreign Languages]]></category>
		<category><![CDATA[I18N]]></category>
		<category><![CDATA[Internationalization]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=270</guid>
		<description><![CDATA[I wanted to make my website bilingual (English and Japanese). There are mainly 3 approaches to internationalize your site.  The URLs below represent how your site&#8217;s top URL will look like for each approach (jp represents the Japanese version) :

http://ainakatani.com/?locale=jp
http://ainakatani.com/jp
http://ainakatani.jp

The last approach requires you to obtain an additional domain, so you may not even consider. You [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to make my website bilingual (English and Japanese). There are mainly 3 approaches to internationalize your site.  The URLs below represent how your site&#8217;s top URL will look like for each approach (jp represents the Japanese version) :</p>
<ol>
<li>http://ainakatani.com/?locale=jp</li>
<li>http://ainakatani.com/jp</li>
<li>http://ainakatani.jp</li>
</ol>
<p>The last approach requires you to obtain an additional domain, so you may not even consider. You can try the first or the second by using I18N (Internationalization Gem).</p>
<p>I tried the first option.</p>
<p>In the next post, I&#8217;ll explain how I did it.</p>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=270</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSS and 502 Bad Gateway Error</title>
		<link>http://railsblog.ainakatani.com/?p=253</link>
		<comments>http://railsblog.ainakatani.com/?p=253#comments</comments>
		<pubDate>Wed, 09 Jun 2010 23:00:05 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Handling Errors]]></category>

		<guid isPermaLink="false">http://railsblog.ainakatani.com/?p=253</guid>
		<description><![CDATA[I made my portfolio here:  http://ainakatani.com
I&#8217;m displaying my recent twitter and blog posts on the top page using rss.
Problem:
About one out of 5 times, I get 502 Bad Gateway Error because my controller failed to get the information from my blog (or twitter)&#8217;s rss.
The error looked like this:
-------------------------------------
OpenURI::HTTPError in HomeController#index
502 Bad Gateway Error

/usr/lib64/ruby/1.8/open-uri.rb:277:in `open_http'
/usr/lib64/ruby/1.8/open-uri.rb:616:in `buffer_open'
/usr/lib64/ruby/1.8/open-uri.rb:164:in [...]]]></description>
			<content:encoded><![CDATA[<p>I made my portfolio here:  <a title="Ai Nakatani's Website" href="http://ainakatani.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/ainakatani.com?referer=');">http://ainakatani.com</a></p>
<p>I&#8217;m displaying my recent twitter and blog posts on the top page using rss.</p>
<h3>Problem:</h3>
<p>About one out of 5 times, I get 502 Bad Gateway Error because my controller failed to get the information from my blog (or twitter)&#8217;s rss.</p>
<p>The error looked like this:</p>
<pre style="font: normal normal normal 12px/18px Consolas, Monaco, 'Courier New', Courier, monospace;"><span style="color: #000000;">-------------------------------------</span></pre>
<h3><span style="color: #808080;">OpenURI::HTTPError in HomeController#index</span></h3>
<p><span style="color: #808080;">502 Bad Gateway Error</span></p>
<div id="Application-Trace">
<pre><code><span style="color: #808080;">/usr/lib64/ruby/1.8/open-uri.rb:277:in `open_http'
/usr/lib64/ruby/1.8/open-uri.rb:616:in `buffer_open'
/usr/lib64/ruby/1.8/open-uri.rb:164:in `open_loop'
/usr/lib64/ruby/1.8/open-uri.rb:162:in `catch'
/usr/lib64/ruby/1.8/open-uri.rb:162:in `open_loop'
/usr/lib64/ruby/1.8/open-uri.rb:132:in `open_uri'
/usr/lib64/ruby/1.8/open-uri.rb:518:in `open'
/usr/lib64/ruby/1.8/open-uri.rb:30:in `open'
/home2/myproject/rails/project1/app/controllers/home_controller.rb:13:in `index'</span></code></pre>
<pre><span style="color: #000000;">-------------------------------------</span></pre>
<h3>Solution:</h3>
<p>I put the code in <strong>begin</strong> and <strong>rescue</strong> block (just like <strong>try</strong> and <strong>catch</strong> block in Java).</p>
<p>My controller looks like this:</p>
<p>require &#8216;rss&#8217;</p>
<p>def index</p>
<p style="padding-left: 30px;">begin</p>
<p style="padding-left: 60px;"><span style="white-space: pre;"> </span>rss = RSS::Parser.parse(open(&#8220;http://blog.ainakatani.com/?feed=rss2&#8243;).read, false)</p>
<p style="padding-left: 60px;">@rss_blog = rss.items[0]</p>
<p style="padding-left: 60px;"><span style="white-space: pre;"> </span>@blog_success = true</p>
<p style="padding-left: 30px;"><span style="white-space: pre;"> </span>rescue</p>
<p style="padding-left: 60px;"><span style="white-space: pre;"> </span>@blog_success = false</p>
<p style="padding-left: 30px;"><span style="white-space: pre;"> </span>end</p>
<p>end</p>
<p>Now, in my view, I added a piece of code looks like this:</p>
<p>&lt;% if @blog_success %&gt;</p>
<p style="padding-left: 30px;"><span style="white-space: pre;"> </span>&lt;p&gt;&lt;%= @rss_blog.title %&gt;&lt;/p&gt;</p>
<p style="padding-left: 30px;"><span style="white-space: pre;"> </span>&lt;p&gt;&lt;%= @rss_blog.description %&gt;&lt;/p&gt;</p>
<p>&lt;% end %&gt;</p>
<p>Now the recent post will be displayed <span style="text-decoration: underline;">only if</span> the controller could succeed to get the information.</p>
</div>
<p><a href="http://www.addtoany.com/share_save?linkurl=&amp;linkname=RSS%20and%20502%20Bad%20Gateway%20Error" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save?linkurl=_amp_linkname=RSS_20and_20502_20Bad_20Gateway_20Error&amp;referer=');"><img src="http://static.addtoany.com/buttons/share_save_256_24.png" alt="Share" /></a></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">require &#8216;rss&#8217;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">def index</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>begin</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>rss = RSS::Parser.parse(open(&#8220;http://blog.ainakatani.com/?feed=rss2&#8243;).read, false)</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>@rss_blog = rss.items[0]</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>@blog_success = true</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>rescue</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>@blog_success = false</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>end</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">end</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Now, in my view, I added a piece of code looks like this:</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;% if @blog_success %&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>&lt;p&gt;&lt;%= @rss_blog.title %&gt;&lt;/p&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span>&lt;p&gt;&lt;%= @rss_blog.description %&gt;&lt;/p&gt;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 515px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;% end %&gt;</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=253</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Meta tags on RoR</title>
		<link>http://railsblog.ainakatani.com/?p=252</link>
		<comments>http://railsblog.ainakatani.com/?p=252#comments</comments>
		<pubDate>Fri, 04 Jun 2010 06:53:03 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://ailoveruby.wordpress.com/?p=252</guid>
		<description><![CDATA[On my website Mixed Baby Name, I have a dedicated page for each baby name.  For example, the name Ai is on this page.
Because I use layout &#8216;application&#8216;, by default, all of the pages&#8217; title, keywords, and description were same as specified in layouts/application.html.erb
I wanted to show a baby name on the browser tab (title) [...]]]></description>
			<content:encoded><![CDATA[<p>On my website <a title="Mixed Baby Name" href="http://www.mixedbabyname.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mixedbabyname.com?referer=');">Mixed Baby Name</a>, I have a dedicated page for each baby name.  For example, the name Ai is on <a title="Ai - Mixed Baby Name" href="http://mixedbabyname.com/babynames/62" target="_blank" onclick="pageTracker._trackPageview('/outgoing/mixedbabyname.com/babynames/62?referer=');">this page</a>.</p>
<p>Because I use <strong>layout &#8216;application</strong>&#8216;, by default, all of the pages&#8217; title, keywords, and description were same as specified in <em><strong>layouts/application.html.erb</strong></em></p>
<p>I wanted to show a baby name on the browser tab (title) so that when the multiple pages are open on tabs, the users will know which page is on which tab. Bookmarking would also be easier.</p>
<p>I found this article by SEO on Rails very useful: <a title="SEO on Rails article" href="http://www.seoonrails.com/getting-your-meta-tags-on-track.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.seoonrails.com/getting-your-meta-tags-on-track.html?referer=');">Getting your meta tags on track </a></p>
<p>Now each of the name pages has a unique title.  Also, when you click on a flag, the new page title also contains the region name.</p>
<p><a href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Failoveruby.wordpress.com%2F2010%2F06%2F04%2Fmeta-tags-on-ror%2F&amp;linkname=Meta%20tags%20on%20RoR" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Failoveruby.wordpress.com_2F2010_2F06_2F04_2Fmeta-tags-on-ror_2F_amp_linkname=Meta_20tags_20on_20RoR&amp;referer=');"><img src="http://static.addtoany.com/buttons/share_save_256_24.png" alt="Share" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=252</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to clean up whitespace</title>
		<link>http://railsblog.ainakatani.com/?p=239</link>
		<comments>http://railsblog.ainakatani.com/?p=239#comments</comments>
		<pubDate>Fri, 04 Jun 2010 00:00:21 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Ruby Operations]]></category>

		<guid isPermaLink="false">http://ailoveruby.wordpress.com/?p=239</guid>
		<description><![CDATA[Sometimes when you ask a user an input, he/she may include white space before/after the actual input by mistake.
You may want to clean them up before saving the input into the database.
Same can be said when the user performs a search.  On my website Mixed Baby Name, if the user types
&#8216;Ai    &#8217;
or
&#8216;    Ai&#8217;
or [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">Sometimes when you ask a user an input, he/she may include white space before/after the actual input by mistake.</div>
<div>You may want to clean them up before saving the input into the database.</div>
<div>Same can be said when the user performs a search.  On my website <a title="Mixed Baby Name" href="http://www.mixedbabyname.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mixedbabyname.com?referer=');">Mixed Baby Name</a>, if the user types</div>
<div style="padding-left:30px;">&#8216;Ai    &#8217;</div>
<div>or</div>
<div style="padding-left:30px;">&#8216;    Ai&#8217;</div>
<div>or even worse,</div>
<div style="padding-left:30px;">&#8216;    Ai     &#8216;</div>
<div>instead of  just &#8216;Ai&#8217; to look for my name, I have to make sure that the user won&#8217;t get an empty result.</div>
<div>The method you are looking for is <strong><span style="color:#ff0000;">strip</span></strong>.</div>
<div>I find <span style="color:#ff0000;"><strong>strip!</strong></span> (with the ! mark) very useful, because it does a strip <span style="text-decoration:underline;">in place</span>.</div>
<div>For your models, you can write a piece of code like this in your model to ensure that your records won&#8217;t have any white space at the beginning and end.</div>
<div style="padding-left:30px;">class<em> Babyname</em> &lt; ActiveRecord::Base</div>
<div id="_mcePaste" style="padding-left:60px;"><span style="color:#ff0000;"><strong>before_validation :</strong></span><em>delete_whitespace</em></div>
<div id="_mcePaste" style="padding-left:60px;"><span style="color:#ff0000;"><strong>def</strong></span> <em>d</em><em>elete_whitespace</em></div>
<div id="_mcePaste" style="padding-left:90px;"><span style="color:#ff0000;"><strong>self.</strong></span><em>name</em>.<span style="color:#ff0000;"><strong>strip! </strong></span></div>
<div id="_mcePaste" style="padding-left:60px;"><strong><span style="color:#ff0000;">end</span></strong></div>
<div style="padding-left:30px;">end</div>
<div>This will define and call the function delete_whitespace before any kind of validation happens  (such as presence of other attributes and uniqueness of the attribute, etc.)</div>
<div>You can also want to add a line of code like this  after the strip to ensure that only the first letter is capitalized.</div>
<div style="padding-left:30px;">self.name.<span style="color:#ff0000;"><strong>capitalize!</strong></span></div>
<div>For example, this will change the name entry &#8220;AI&#8221; or &#8220;ai&#8221; into &#8220;Ai&#8221; in place.</div>
<p><a href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Failoveruby.wordpress.com%2F2010%2F06%2F04%2Fhow-to-clean-up-whitespace%2F&amp;linkname=How%20to%20clean%20up%20whitespace" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Failoveruby.wordpress.com_2F2010_2F06_2F04_2Fhow-to-clean-up-whitespace_2F_amp_linkname=How_20to_20clean_20up_20whitespace&amp;referer=');"><img src="http://static.addtoany.com/buttons/share_save_256_24.png" alt="Share" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=239</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joining attributes into a string</title>
		<link>http://railsblog.ainakatani.com/?p=232</link>
		<comments>http://railsblog.ainakatani.com/?p=232#comments</comments>
		<pubDate>Thu, 03 Jun 2010 23:31:26 +0000</pubDate>
		<dc:creator>Ai</dc:creator>
				<category><![CDATA[Ruby Operations]]></category>

		<guid isPermaLink="false">http://ailoveruby.wordpress.com/?p=232</guid>
		<description><![CDATA[If you have multiple objects and you want to show certain attributes as one string, with, for example, a comma in between, you write:
&#60;%= objects.map(&#38;:attribute).join(&#8216;, &#8216;) %&#62;
For example, if I want to output a string consisting some objects(say babynames)&#8217; names, I write:
&#60;%= babynames.map(&#38;:name).join(&#8216;, &#8216;) %&#62;
The output will be something like:
Andrew, Chris, Oliver, Anna
This is nice [...]]]></description>
			<content:encoded><![CDATA[<p>If you have multiple objects and you want to show certain attributes as one string, with, for example, a comma in between, you write:</p>
<p style="padding-left:30px;"><strong><span style="color:#ff0000;">&lt;%=</span> </strong><em>objects</em><strong><span style="color:#ff0000;">.map(&amp;:</span><span style="color:#ff0000;"><span style="font-weight:normal;"><em><span style="color:#000000;">a</span></em><em><span style="color:#000000;">ttribute</span></em></span></span></strong><strong><span style="color:#ff0000;">).joi<span style="color:#ff0000;">n(</span></span><span style="color:#ff0000;">&#8216;</span></strong><em>,</em><strong><span style="color:#ff0000;"> &#8216;) %&gt;</span></strong></p>
<p><span style="color:#ff0000;"><strong><span style="color:#000000;"><span style="font-weight:normal;">For example, if I want to output a string consisting some objects(say babynames)&#8217; names, I write:</span></span></strong></span></p>
<p style="padding-left:30px;"><span style="color:#ff0000;"><strong><span style="color:#000000;"><span style="font-weight:normal;"><strong>&lt;%= </strong><em>babynames</em><strong>.map(&amp;:</strong><em>name</em><strong>).join(&#8216;</strong><em>,</em><strong> &#8216;) %&gt;</strong></span></span></strong></span></p>
<p>The output will be something like:</p>
<p style="padding-left:30px;">Andrew, Chris, Oliver, Anna</p>
<p>This is nice because you don&#8217;t have to write a loop and check whether to add a comma (or period or whatever) after each name.</p>
<p><a href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Failoveruby.wordpress.com%2F2010%2F06%2F03%2Fjoining-multiple-strings%2F&amp;linkname=Joining%20multiple%20strings" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save?linkurl=http_3A_2F_2Failoveruby.wordpress.com_2F2010_2F06_2F03_2Fjoining-multiple-strings_2F_amp_linkname=Joining_20multiple_20strings&amp;referer=');"><img src="http://static.addtoany.com/buttons/share_save_256_24.png" alt="Share" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://railsblog.ainakatani.com/?feed=rss2&amp;p=232</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

