<?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>42 &#187; ruby on rails</title>
	<atom:link href="http://www.42.mach7x.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.42.mach7x.com</link>
	<description>Thoughts and tips about programming with Ruby on Rails</description>
	<lastBuildDate>Fri, 06 Aug 2010 11:57:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>God gem problem unpacking with Rails 2.3.2</title>
		<link>http://www.42.mach7x.com/2010/08/06/god-gem-problem-unpacking-with-rails-2-3-2/</link>
		<comments>http://www.42.mach7x.com/2010/08/06/god-gem-problem-unpacking-with-rails-2-3-2/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 11:14:16 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[God gem]]></category>
		<category><![CDATA[Rails 2.3.2]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=212</guid>
		<description><![CDATA[Problem When using the god gem in a Rails 2.3.2 application, when you unpack (freeze) the god gem with : sudo rake gems:unpack it creates the god drectory in vendor/gems with root owner, and group permissions. Solution Remember to change owner and group for the folder sudo chown -R user_name vendor/gems/god-0.11.0 sudo chown -R user_name [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
When using the god gem in a Rails 2.3.2 application, when you unpack (freeze) the god gem with :</p>
<p><span class="code">sudo rake gems:unpack</span></p>
<p>it creates the god drectory in vendor/gems with root owner, and group permissions.</p>
<p><strong>Solution</strong><br />
Remember to change owner and group for the folder</p>
<p><span class="code">sudo chown -R user_name vendor/gems/god-0.11.0<br />
sudo chown -R user_name vendor/gems/god-0.11.0</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/08/06/god-gem-problem-unpacking-with-rails-2-3-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Help! I&#8217;m getting the message &#8220;libMagickWand.so.1: cannot open shared object file: No such file or directory&#8221; I know ImageMagick is installed! What should I do?</title>
		<link>http://www.42.mach7x.com/2010/07/13/help-im-getting-the-message-libmagickwand-so-1-cannot-open-shared-object-file-no-such-file-or-directory-i-know-imagemagick-is-installed-what-should-i-do/</link>
		<comments>http://www.42.mach7x.com/2010/07/13/help-im-getting-the-message-libmagickwand-so-1-cannot-open-shared-object-file-no-such-file-or-directory-i-know-imagemagick-is-installed-what-should-i-do/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 16:20:01 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[LD_LIBRARY_PATH]]></category>
		<category><![CDATA[Rmagick]]></category>
		<category><![CDATA[shared libraries]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=203</guid>
		<description><![CDATA[Problem Cannot install RMagick as there is an error about nob being able to find some shared libraries. Solution After reading the RMagick installation FAQ it seem there is a problem with the LD_LIBRARY_PATH that cannot find the needed libraries as they are installed in /usr/local/lib instead of /usr/lib. Doing a quick search revealed that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
Cannot install RMagick as there is an error about nob being able to find some shared libraries.</p>
<p><strong>Solution</strong><br />
After reading the RMagick installation FAQ it seem there is a problem with the LD_LIBRARY_PATH that cannot find the needed libraries as they are installed in /usr/local/lib instead of /usr/lib.<br />
Doing a quick search revealed that people suggest that the LD_LIBRARY_PATH shouldn&#8217;t be changed, for various reasons.<br />
So, the quick solution is to create a couple of symbolic links for the libraries that cannot be found, ie:</p>
<p><span class="code">sudo ln -s /usr/local/lib/libMagickWand.so.4 /usr/lib/libMagickWand.so.4<br />
ln -s /usr/local/lib/libMagickCore.so.4 /usr/lib/libMagickCore.so.4</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/07/13/help-im-getting-the-message-libmagickwand-so-1-cannot-open-shared-object-file-no-such-file-or-directory-i-know-imagemagick-is-installed-what-should-i-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails find case sensitive search</title>
		<link>http://www.42.mach7x.com/2010/05/17/rails-find-case-sensitive-search/</link>
		<comments>http://www.42.mach7x.com/2010/05/17/rails-find-case-sensitive-search/#comments</comments>
		<pubDate>Mon, 17 May 2010 16:14:48 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[BINARY]]></category>
		<category><![CDATA[Case insensitive]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=200</guid>
		<description><![CDATA[Problem You want to use find in Rails for a case sensitive search. For example in your authentication logic you have something to find the user to login as in: u=User.find_by_login(&#8216;username&#8217;) If you don&#8217;t want to limit the available logins with case insensitive validation in the model, then the above code will not work if [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to use find in Rails for a case sensitive search. For example in your authentication logic you have something to find the user to login as in:<br />
<span class="code">u=User.find_by_login(&#8216;username&#8217;)</span><br />
If you don&#8217;t want to limit the available logins with case insensitive validation in the model, then the above code will not work if you have &#8216;Username&#8217; and &#8216;username&#8217; as available logins, as the find will only return one of them.</p>
<p><strong>Solution</strong><br />
Change the find method to use the BINARY keyword in your database (only used with MySQL), as in the following:<br />
<span class="code">u=User.find(:first, :conditions => ["BINARY login = ?", login])</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/05/17/rails-find-case-sensitive-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>406 Not Acceptable &#8211; Princely &#8211; Dreamhost</title>
		<link>http://www.42.mach7x.com/2010/04/22/406-not-acceptable-princely-dreamhost/</link>
		<comments>http://www.42.mach7x.com/2010/04/22/406-not-acceptable-princely-dreamhost/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 10:14:42 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Prince XML]]></category>
		<category><![CDATA[princely]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=193</guid>
		<description><![CDATA[Problem You get a &#8217;406 Not Acceptable&#8217; response from the web server when you try to use the princely plugin for generating pdf on a Ruby on Rails application hosted on dreamhost. Solution Having tried the &#8216;Extra Web Security&#8217; settings in dreamhost Web panel, and setting them on/off did not get very far. Also setting [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You get a &#8217;406 Not Acceptable&#8217;  response from the web server when you try to use the princely plugin for generating pdf on a Ruby on Rails application hosted on dreamhost.</p>
<p><strong>Solution</strong><br />
Having tried the &#8216;Extra Web Security&#8217; settings in dreamhost Web panel, and setting them on/off did not get very far.<br />
Also setting up an .htaccess file didn&#8217;t seem to make any difference.<br />
So the mod_security settings did not seem to be the cause of the problem.<br />
Having a look at the apache error log files which in the case of the dreamhost ps are in /usr/local/dh/apache2/logs/apache2-ps_name it turns out that the problem was that the path for the prince binary was not setting up correctly in the file vendor/plugins/princely/lib/prince.rb on line 26.<br />
A quick hack to make it work until finding the reason for the problem is to hardcode the path to the prince binary, so:<br />
<span class="code">@exe_path = `which prince`.chomp<br />
if @exe_path.nil?<br />
  @exe_path=&#8217;/usr/local/bin/prince&#8217;<br />
end</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/04/22/406-not-acceptable-princely-dreamhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Could not load SystemTimer gem, falling back to Ruby&#8217;s slower/unsafe timeout library: no such file to load &#8212; system_timer</title>
		<link>http://www.42.mach7x.com/2010/04/14/could-not-load-systemtimer-gem-falling-back-to-rubys-slowerunsafe-timeout-library-no-such-file-to-load-system_timer/</link>
		<comments>http://www.42.mach7x.com/2010/04/14/could-not-load-systemtimer-gem-falling-back-to-rubys-slowerunsafe-timeout-library-no-such-file-to-load-system_timer/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 08:40:56 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[beta3]]></category>
		<category><![CDATA[Rails 2.3.2]]></category>
		<category><![CDATA[Rails 3]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=189</guid>
		<description><![CDATA[Problem You have the error showing up after starting either the server (./script/server) or the console (./script/console). For my particular case it started appearing after installing the Rails 3.0 beta3 version, and in an application developed with Rails 2.3.2. Solution Just install the system_timer gem: sudo gem install system_timer]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You have the error showing up after starting either the server (./script/server) or the console (./script/console).<br />
For my particular case it started appearing after installing the Rails 3.0 beta3 version, and in an application developed with Rails 2.3.2.</p>
<p><strong>Solution</strong><br />
Just install the system_timer gem:<br />
<span class="code">sudo gem install system_timer</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/04/14/could-not-load-systemtimer-gem-falling-back-to-rubys-slowerunsafe-timeout-library-no-such-file-to-load-system_timer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NoMethodError (undefined method `refresh_token&#8217; for #):</title>
		<link>http://www.42.mach7x.com/2010/03/26/nomethoderror-undefined-method-refresh_token-for/</link>
		<comments>http://www.42.mach7x.com/2010/03/26/nomethoderror-undefined-method-refresh_token-for/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 15:52:48 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Mandriva]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=187</guid>
		<description><![CDATA[Problem When you get the above error you cannot login to your application. Solution You will need to delete the cookies for the authentication, so in Firefox (Linux) go to Preferences, remove individual cookies for the specific domain.]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
When you get the above error you cannot login to your application.</p>
<p><strong>Solution</strong><br />
You will need to delete the cookies for the authentication, so in Firefox (Linux) go to Preferences, remove individual cookies for the specific domain.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/03/26/nomethoderror-undefined-method-refresh_token-for/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>undefined method &#8216;remap&#8217; for class &#8216;Magick::Image&#8217;</title>
		<link>http://www.42.mach7x.com/2010/03/18/undefined-method-remap-for-class-magickimage/</link>
		<comments>http://www.42.mach7x.com/2010/03/18/undefined-method-remap-for-class-magickimage/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 10:13:10 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Magick]]></category>
		<category><![CDATA[Remap]]></category>
		<category><![CDATA[Rmagick]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=180</guid>
		<description><![CDATA[Problem You have just deployed your rails application to dreamhost but you are getting this error from passenger. Solution There was a change in the ImageMagic between versions 6.4.3 and 6.4.4 from the affinity function to remap. If you don&#8217;t want, or don&#8217;t have time to recompile the ImageMagick and install the rmagick gem, you [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You have just deployed your rails application to dreamhost but you are getting this error from passenger.</p>
<p><strong>Solution</strong><br />
There was a change in the ImageMagic between versions 6.4.3 and 6.4.4 from the affinity function to remap.<br />
If you don&#8217;t want, or don&#8217;t have time to recompile the ImageMagick and install the rmagick gem, you can comment out the two declarations for the alias functions, located around lines 782 and 1525 in the file rmagick-2.12.2/lib/RMagick.rb:</p>
<p><span class="code">alias_method :affinity, :remap</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/03/18/undefined-method-remap-for-class-magickimage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Freezing rails to an older version using gems</title>
		<link>http://www.42.mach7x.com/2010/03/15/freezing-rails-to-an-older-version-using-gems/</link>
		<comments>http://www.42.mach7x.com/2010/03/15/freezing-rails-to-an-older-version-using-gems/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 10:43:45 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[2.3.2]]></category>
		<category><![CDATA[freezing]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=178</guid>
		<description><![CDATA[Problem You want to deploy to a shared host (dreamhost) that has a later version of rails from the one you have developed your application. You also have a later version installed in your development pc,and using rake rails:freeze:gems uses the latest one and not the one you want. Solution Use the following to freeze [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to deploy to a shared host (dreamhost) that has a later version of rails from the one you have developed your application.<br />
You also have a later version installed in your development pc,and using rake rails:freeze:gems uses the latest one and not the one you want.</p>
<p><strong>Solution</strong><br />
Use the following to freeze the specific version you want, and by using your gems you have installed:<br />
<span class="code">rake rails:freeze:gems VERSION=2.3.2</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/03/15/freezing-rails-to-an-older-version-using-gems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>replacing comma with and in a list with ruby</title>
		<link>http://www.42.mach7x.com/2010/02/23/replacing-comma-with-and-in-a-list-with-ruby/</link>
		<comments>http://www.42.mach7x.com/2010/02/23/replacing-comma-with-and-in-a-list-with-ruby/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:47:51 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[and]]></category>
		<category><![CDATA[commas]]></category>
		<category><![CDATA[replacing]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=162</guid>
		<description><![CDATA[Problem You have a list, usually after using join(&#8220;,&#8221;) in an array that consists of different values ie &#8220;one, two, three, four&#8221;, but you want to replace the last comma with and so it would be &#8220;one, two, three and four&#8221;. Solution Use reverse initially to reverse the string, then use sub to replace the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You have a list, usually after using join(&#8220;,&#8221;) in an array that consists of different values ie &#8220;one, two, three, four&#8221;, but you want to replace the last comma with and so it would be &#8220;one, two, three and four&#8221;.</p>
<p><strong>Solution</strong><br />
Use reverse initially to reverse the string, then use sub to replace the last comma with the word and reversed (dna), and then finally reverse the string again.</p>
<p><span class="code">string_with_and=string_with_commas.reverse.sub(/,/, &#8216; dna &#8216;).reverse</span</p>
<p>or, thanks to Akhil's comment, for Arrays in Rails we can use the to_sentence method as in:</p>
<p><span class="code">string_with_no_commas=array.to_sentence(options = {:last_word_connector => &#8221; and &#8220;})</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/02/23/replacing-comma-with-and-in-a-list-with-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NoMethodError: Attempt to call private method in using Geokit rake task</title>
		<link>http://www.42.mach7x.com/2010/01/06/nomethoderror-attempt-to-call-private-method-in-using-geokit-rake-task/</link>
		<comments>http://www.42.mach7x.com/2010/01/06/nomethoderror-attempt-to-call-private-method-in-using-geokit-rake-task/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 12:32:56 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Geokit]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[rake]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=159</guid>
		<description><![CDATA[Problem Trying to use the rake task for populating latitude and longitude details for addresses as described in the Web mashup projects book, gives the error about attempting to call private method. Solution Use the method save instead of update as suggested in the book.]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
Trying to use the rake task for populating latitude and longitude details for addresses as described in the Web mashup projects book, gives the error about attempting to call private method.</p>
<p><strong>Solution</strong><br />
Use the method save instead of update as suggested in the book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2010/01/06/nomethoderror-attempt-to-call-private-method-in-using-geokit-rake-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
