<?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/tag/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>Wed, 01 Feb 2012 14:38:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Polymorphic associations&#8217; as and where is used in SQL</title>
		<link>http://www.42.mach7x.com/2011/09/27/polymorphic-associations-as-and-where-is-used-in-sql/</link>
		<comments>http://www.42.mach7x.com/2011/09/27/polymorphic-associations-as-and-where-is-used-in-sql/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 12:35:30 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[polymorphic association]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=425</guid>
		<description><![CDATA[Problem You are using a polymorphic association in your application, and you would like to know how exactly the as declaration in your model has_many is used in the SQL by ActiveRecord. So following the example in the Rails Guides with the following models: &#160; class Picture &#60; ActiveRecord::Base belongs_to :imageable, :polymorphic =&#62; true end [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong></p>
<p>You are using a polymorphic association in your application, and you would like to know how exactly the as declaration in your model has_many is used in the SQL by ActiveRecord. So following the example in the Rails Guides with the following models:</p>
<p>&nbsp;</p>
<pre class="brush:ruby">class Picture &lt; ActiveRecord::Base
  belongs_to :imageable, :polymorphic =&gt; true
end

class Employee &lt; ActiveRecord::Base
  has_many :pictures, :as =&gt; :imageable
end

class Product &lt; ActiveRecord::Base
  has_many :pictures, :as =&gt; :imageable
end</pre>
<p><strong>Solution </strong></p>
<p>ActiveRecord uses the as in the model declaration as a guide to find the foreign id key in the polymorphic association, by adding the _id to the :as name. So following the<br />
example above the query for the product would be:</p>
<pre class="brush:ruby">SELECT `images`.*
FROM `images`
WHERE (`ratings`.imageable_id = 289
      AND `images`.imageable_type = 'Product')</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/09/27/polymorphic-associations-as-and-where-is-used-in-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passenger (mod_rails) gem installation &#8211; Apache2 &#8211; Debian &#8211; rvm</title>
		<link>http://www.42.mach7x.com/2011/09/08/passenger-mod_rails-gem-installation-apache2-debian-rvm/</link>
		<comments>http://www.42.mach7x.com/2011/09/08/passenger-mod_rails-gem-installation-apache2-debian-rvm/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 07:43:01 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Phusion Passenger]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[Passenger]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=400</guid>
		<description><![CDATA[Problem You would like to (re)-install passenger after a system wide rvm installation, but you only have the mod_passenger.c file and not the .so after the gem installation. Solution Make sure that after using gem install passenger you also use the command to install the apache2 passenger module: passenger-install-apache2-module you should then be able to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You would like to (re)-install passenger after a system wide rvm installation, but you only have the mod_passenger.c file and not the .so after the gem installation.</p>
<p><strong>Solution</strong><br />
Make sure that after using gem install passenger you also use the command to install the apache2 passenger module:</p>
<p><code>passenger-install-apache2-module</code></p>
<p>you should then be able to see the .so file and add it to your /etc/apache2/mods-available/passenger.load</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/09/08/passenger-mod_rails-gem-installation-apache2-debian-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Could not find generator jquery:install</title>
		<link>http://www.42.mach7x.com/2011/08/31/could-not-find-generator-jqueryinstall/</link>
		<comments>http://www.42.mach7x.com/2011/08/31/could-not-find-generator-jqueryinstall/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 14:14:01 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=392</guid>
		<description><![CDATA[Problem When you try to replace prototype with jquery in your Rails 3.0.x application, by using the command described in the Agile Web development book: rails generate jquery:install --ui --force you get the following error: Could not find generator jquery:install Solution You would need to follow the steps below: Add gem &#8220;jquery-rails&#8221;, &#8220;~> 1.0.13&#8243; in [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
When you try to replace prototype with jquery in your Rails 3.0.x application, by using the command described in the Agile Web development book:</p>
<p><code>rails generate jquery:install --ui --force</code></p>
<p>you get the following error:</p>
<p><code>Could not find generator jquery:install</code></p>
<p><strong>Solution</strong><br />
You would need to follow the steps below:</p>
<ol>
<li>Add gem &#8220;jquery-rails&#8221;, &#8220;~> 1.0.13&#8243; in your Gemfile, and run bundle install</li>
<li>run the command described above: rails generate jquery:install &#8211;ui &#8211;force</li>
</ol>
<p>Now you should be able to see something like:</p>
<p><code>remove  public/javascripts/prototype.js<br />
      remove  public/javascripts/effects.js<br />
      remove  public/javascripts/dragdrop.js<br />
      remove  public/javascripts/controls.js<br />
     copying  jQuery (1.6.2)<br />
      create  public/javascripts/jquery.js<br />
      create  public/javascripts/jquery.min.js<br />
     copying  jQuery UI (1.8.14)<br />
      create  public/javascripts/jquery-ui.js<br />
      create  public/javascripts/jquery-ui.min.js<br />
     copying  jQuery UJS adapter (cd619d)<br />
      remove  public/javascripts/rails.js<br />
      create  public/javascripts/jquery_ujs.js</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/08/31/could-not-find-generator-jqueryinstall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing associations in Rspec</title>
		<link>http://www.42.mach7x.com/2011/07/22/testing-associations-in-rspec/</link>
		<comments>http://www.42.mach7x.com/2011/07/22/testing-associations-in-rspec/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 09:06:15 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[RSpec]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[belons_to]]></category>
		<category><![CDATA[has_many]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=373</guid>
		<description><![CDATA[Problem You would like to test your model associations in an RSpec model spec, to make sure that they are correctly set up. Solution After some Google searching and coming across this article here, ended up using the second method described there with the reflect_on_association method, as it doesn&#8217;t need the inclusion of another gem. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You would like to test your model associations in an RSpec model spec, to make sure that they are correctly set up.</p>
<p><strong>Solution</strong><br />
After some Google searching and coming across this article <a href="http://liahhansen.com/2011/04/14/testing-model-associations-in-rspec.html">here</a>, ended up using the second method described there with the reflect_on_association method, as it doesn&#8217;t need the inclusion of another gem.<br />
So for example to to test multiple has_many or belongs_to associations in your model rspec you could use something like:<br />
<code>context "check associations" do<br />
    # belongs_to associations<br />
    %w{bel_to1 bel_to2}.each do |bt|<br />
      it "should belong to #{bt}" do<br />
        m = Model.reflect_on_association(:"#{bt}")<br />
        m.macro.should == :belongs_to<br />
      end<br />
    end<br />
    # has_many associations<br />
    %w{has_many1 has_many2 has_many3}.each do |hm|<br />
      it "should have many #{hm}" do<br />
        m = Model.reflect_on_association(:"#{hm}")<br />
        m.macro.should == :has_many<br />
      end<br />
    end<br />
  end</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/07/22/testing-associations-in-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The single-table inheritance mechanism failed to locate the subclass:</title>
		<link>http://www.42.mach7x.com/2011/07/22/the-single-table-inheritance-mechanism-failed-to-locate-the-subclass/</link>
		<comments>http://www.42.mach7x.com/2011/07/22/the-single-table-inheritance-mechanism-failed-to-locate-the-subclass/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 08:57:52 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[3.0.9]]></category>
		<category><![CDATA[Single Table Inheritance]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=370</guid>
		<description><![CDATA[Problem You have correctly setup your Single Table Inheritance tables as in: class Parent < ActieRecord::Base ; end class Child < Parent ; end but everytime you are trying to use that in a cucumber feature, or in rails console you get the following error: The single-table inheritance mechanism failed to locate the subclass: 'child'. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You have correctly setup your Single Table Inheritance tables as in:</p>
<p><code>class Parent < ActieRecord::Base ; end<br />
class Child < Parent ; end</code></p>
<p>but everytime you are trying to use that in a cucumber feature, or in rails console you get the following error:</p>
<p><code>The single-table inheritance mechanism failed to locate the subclass: 'child'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Parent.inheritance_column to use another column for that information. (ActiveRecord::SubclassNotFound)</code></p>
<p><strong>Solution</strong><br />
Make sure that when use the subclass name in a feature, or you create a record in the database the initial letter is in capital!<br />
So make sure that in this case the type column contains <strong>'Child'</strong> and not <strong>'child'</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/07/22/the-single-table-inheritance-mechanism-failed-to-locate-the-subclass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google-Maps-Rails (gmaps4rails) does not display markers when upgrading to 0.10.0</title>
		<link>http://www.42.mach7x.com/2011/07/19/google-maps-rails-gmaps4rails-does-not-display-markers-when-upgrading-to-0-10-0/</link>
		<comments>http://www.42.mach7x.com/2011/07/19/google-maps-rails-gmaps4rails-does-not-display-markers-when-upgrading-to-0-10-0/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 16:04:31 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[gmaps4rails]]></category>
		<category><![CDATA[Google-Maps-for-Rails]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=367</guid>
		<description><![CDATA[Problem When upgrading the gmaps4rails gem to version 0.10.0 the markers are not displayed any more on the map. Solution There is an issue raised about the bug here. To make the markers appear downgrade to version 0.9.1 of the gem. update: or upgrade to 0.10.2 as the bug is fixed.]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
When upgrading the gmaps4rails gem to version 0.10.0 the markers are not displayed any more on the map.</p>
<p><strong>Solution</strong><br />
There is an issue raised about the bug <a href="https://github.com/apneadiving/Google-Maps-for-Rails/issues/58" title="here">here</a>.<br />
To make the markers appear downgrade to version 0.9.1 of the gem.</p>
<p><strong>update:</strong> or upgrade to 0.10.2 as the bug is fixed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/07/19/google-maps-rails-gmaps4rails-does-not-display-markers-when-upgrading-to-0-10-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ImageMagick, RMagick, Debian installation</title>
		<link>http://www.42.mach7x.com/2011/06/17/imagemagick-rmagick-debian-installation/</link>
		<comments>http://www.42.mach7x.com/2011/06/17/imagemagick-rmagick-debian-installation/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 08:48:54 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Rmagick]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=349</guid>
		<description><![CDATA[Problem You want to use the rmagick gem in your ruby on rails project, but you need to install the imagemagick first. Solution If Imagemagick is not already installed, use the following to install it: $ sudo apt-get install imagemagick]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to use the rmagick gem in your ruby on rails project, but you need to install the imagemagick first.</p>
<p><strong>Solution</strong><br />
If Imagemagick is not already installed, use the following to install it:<br />
<code>$ sudo apt-get install imagemagick</code/</p>
<p>Then install the development librarires for both the imagemagick and the MagickWand as in:<br />
<code>$ sudo apt get install libmagick-dev libmagickwand-dev</code></p>
<p>You should then be able to install and use the rmagick gem</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/06/17/imagemagick-rmagick-debian-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ImageMagick, RMagick, Mandriva 64 installation</title>
		<link>http://www.42.mach7x.com/2011/06/17/imagemagick-rmagick-mandriva-64-installation/</link>
		<comments>http://www.42.mach7x.com/2011/06/17/imagemagick-rmagick-mandriva-64-installation/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 08:46:18 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Mandriva]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[Mandirva 64]]></category>
		<category><![CDATA[Rmagick]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=347</guid>
		<description><![CDATA[Problem You want to use the rmagick gem in your ruby on rails project, but you need to install the imagemagick first. Solution If Imagemagick is not already installed, use the following to install it: $ sudo urpmi imagemagick]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You want to use the rmagick gem in your ruby on rails project, but you need to install the imagemagick first.</p>
<p><strong>Solution</strong><br />
If Imagemagick is not already installed, use the following to install it:<br />
<code>$ sudo urpmi imagemagick</code/</p>
<p>Then install the development library for the 64bit version as in:<br />
<code>$ sudo urpmi lib64magick-devel</code></p>
<p>You should then be able to install and use the rmagick gem</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/06/17/imagemagick-rmagick-mandriva-64-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Couldn&#8217;t find &#8216;rspec&#8217; generator &#8211; Rails 2.3.10</title>
		<link>http://www.42.mach7x.com/2011/03/08/couldnt-find-rspec-generator-rails-2-3-10/</link>
		<comments>http://www.42.mach7x.com/2011/03/08/couldnt-find-rspec-generator-rails-2-3-10/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 12:08:16 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[RSpec]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[2.3.10]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=325</guid>
		<description><![CDATA[Problem You are trying to use rspec with Ruby on Rails 2.3.10, but although you install the rspec and rspec-rails gems you get the following error when you try to run script/generate rspec Couldn't find 'rspec' generator Solution It turns out that there is a problem with the versions used, so by following the instructions [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You are trying to use rspec with Ruby on Rails 2.3.10, but although you install the rspec and rspec-rails gems you get the following error when you try to run script/generate rspec<br />
<code>Couldn't find 'rspec' generator</code></p>
<p><srrong>Solution</strong><br />
It turns out that there is a problem with the versions used, so by following the instructions for Rails >= 2.3.10 from <a href="https://github.com/dchelimsky/rspec/wiki/rails">here</a>, you should be able to install the plugins and use rspec:<br />
<code>ruby script/plugin install git://github.com/dchelimsky/rspec.git -r 'refs/tags/1.3.1'<br />
ruby script/plugin install git://github.com/dchelimsky/rspec-rails.git -r 'refs/tags/1.3.3'<br />
ruby script/generate rspec</code></p>
<p>where the last tag (1.3.3) should be the latest tag for each gem.</p>
<p>*** NOTE *** If you get an error like :<br />
<code>You have a nil object when you didn't expect it!<br />
You might have expected an instance of Array.<br />
The error occurred while evaluating nil.map (NoMethodError) </code></p>
<p>uncomment the following line (line 11) from features/support/env.rb:<br />
<code>require 'cucumber/rails/rspec'</code><br />
and run rake cucumber again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/03/08/couldnt-find-rspec-generator-rails-2-3-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capistrano output colours</title>
		<link>http://www.42.mach7x.com/2011/03/04/capistrano-output-colours/</link>
		<comments>http://www.42.mach7x.com/2011/03/04/capistrano-output-colours/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 12:12:01 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[colours]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=322</guid>
		<description><![CDATA[Problem You would like to have colours in the output of your capistrano tasks similar to the ones in cucumber, indicating errors (red) or completed actions(green). Solution Install the capistrano_colours gem that can be found here. sudo gem install capistrano_colors]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You would like to have colours in the output of your capistrano tasks similar to the ones in cucumber, indicating errors (red) or completed actions(green).</p>
<p><strong>Solution</strong><br />
Install the capistrano_colours gem that can be found <a href="https://github.com/stjernstrom/capistrano_colors">here</a>.<br />
<code>sudo gem install capistrano_colors</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/03/04/capistrano-output-colours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

