<?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>Neyric.com &#187; rails</title>
	<atom:link href="http://neyric.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://neyric.com</link>
	<description>projects, programming, blogging...</description>
	<lastBuildDate>Sat, 29 Jan 2011 19:51:22 +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>How to delete a many-to-many association with Rails</title>
		<link>http://neyric.com/2007/07/08/how-to-delete-a-many-to-many-association-with-rails/</link>
		<comments>http://neyric.com/2007/07/08/how-to-delete-a-many-to-many-association-with-rails/#comments</comments>
		<pubDate>Sun, 08 Jul 2007 12:59:53 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[association]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[many]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://how-to-delete-a-many-to-many-association-with-rails</guid>
		<description><![CDATA[Judging by the number of Ruby on Rails developpers asking themselves this question, this is the missing example of Rails. (It&#8217;s not in my Rails reference book, and I&#8217;ve never seen any example on any blog.) One solution is to &#8230; <a href="http://neyric.com/2007/07/08/how-to-delete-a-many-to-many-association-with-rails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Judging by the number of Ruby on Rails developpers asking themselves this question,<br />
this is the missing example of Rails. (It&#8217;s not in my Rails reference book, and<br />
I&#8217;ve never seen any example on any blog.)</p>
<p>One solution is to create a new model for the association. It <b>schould</b> be the case<br />
if you add attributes to the association (because <i>push_with_attributes</i> is now deprecated).<br />
You can then simply find the association given the ids of your linked object and call destroy.</p>
<p>However, when you don&#8217;t have any attribute in your liaison, the <i>has_and_belongs_to_many</i><br />
is nicer to work with. (you don&#8217;t need a rails model for the liaison.)<br />
Here is a link to the methods <a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000645"><br />
<i>has_and_belongs_to_many</i> adds</a> where we can read :</p>
<p></p>
<pre>"collection.delete(object, …) - removes one or more objects from the
collection by removing their associations from the join table.
This does not destroy the objects."
</pre>
<p></p>
<p>Let&#8217;s assume we dispose of 2 models &#8216;Post&#8217; and &#8216;Category&#8217; with a N-N association :</p>
<pre>class Post &lt; ActiveRecord::Base
  has_and_belongs_to_many :categories
end

class Category &lt; ActiveRecord::Base
  has_and_belongs_to_many :posts
end
</pre>
<p>To delete an association (remove a post from a category) you can use this method :</p>
<pre>  def remove_post_from_category
     post = Post.find(params[:post][:id])
     category = post.categories.find(params[:category][:id])

     if category
        post.categories.delete(category)
     end

  end
</pre>
<p>This function will destroy the association but <b>won&#8217;t</b> destroy the category.</p>
<p>You can also removes all the categories from the posts by using :</p>
<p></p>
<pre>collection.clear - removes every object from the collection.
This does not destroy the objects.</pre>
<p></p>
<p>In our example :</p>
<pre>
post.categories.clear
</pre>
<div class="shr-publisher-61"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2007/07/08/how-to-delete-a-many-to-many-association-with-rails/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Get rid of favicon.ico 404 errors with rails</title>
		<link>http://neyric.com/2007/07/07/get-rid-of-faviconico-404-errors-with-rails/</link>
		<comments>http://neyric.com/2007/07/07/get-rid-of-faviconico-404-errors-with-rails/#comments</comments>
		<pubDate>Sat, 07 Jul 2007 17:29:01 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[favicon.ico]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://get-rid-of-faviconico-404-errors-with-rails</guid>
		<description><![CDATA[Every time your browser loads an new url, it also request a file called &#8216;favicon.ico&#8217; in the same subdirectory. This generates a LOT of errors in the Ruby on Rails logs of my app. One way to avoid those errors &#8230; <a href="http://neyric.com/2007/07/07/get-rid-of-faviconico-404-errors-with-rails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Every time your browser loads an new url, it also request a file<br />
called &#8216;favicon.ico&#8217; in the same subdirectory. This generates a LOT of<br />
errors in the Ruby on Rails logs of my app.</p>
<p>One way to avoid those errors is to redirect the browser to the root /favicon.ico file.<br />
Just add this line in the /public/.htaccess file of your rails project :</p>
<pre style="background-color: black;color: white"> RewriteRule ^(.*)favicon.ico$ favicon.ico [QSA]
</pre>
<p>Do you use another method to resolve this problem ?</p>
<div class="shr-publisher-59"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2007/07/07/get-rid-of-faviconico-404-errors-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>has_and_belongs_to_many or has_many :through?</title>
		<link>http://neyric.com/2007/02/10/hasandbelongstomany-or-hasmany-through/</link>
		<comments>http://neyric.com/2007/02/10/hasandbelongstomany-or-hasmany-through/#comments</comments>
		<pubDate>Sat, 10 Feb 2007 17:51:19 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[has_and_belongs_to_many]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[through]]></category>

		<guid isPermaLink="false">http://hasandbelongstomany-or-hasmany-through</guid>
		<description><![CDATA[As you may (or may not) know, there are two ways to build a many-to-many (or N-N) relationship with Rails. The first way uses has_and_belongs_to_many in both models. You&#8217;ll have to create a join table that has no corresponding model &#8230; <a href="http://neyric.com/2007/02/10/hasandbelongstomany-or-hasmany-through/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As you may (or may not) know, there are two ways to build a many-to-many (or N-N) relationship with Rails.</p>
<ol>
<li>The first way uses <span style="font-style: italic;">has_and_belongs_to_many</span> in both models. You&#8217;ll have to create a join table that has no corresponding model or primary key. ( ActiveRecord will look by default for a join table called <span style="font-style: italic;">groups_users</span> )</li>
<p><code>class Group &lt; ActiveRecord::Base<br />
has_and_belongs_to_many :users # foreign keys in the join table<br />
end<br />
class User &lt; ActiveRecord::Base<br />
has_and_belongs_to_many :groups # foreign keys in the join table<br />
end</code></p>
<p><code><br />
The join table can have more attributes which can be filled with the <span style="font-style: italic;">push_with_attributes</span> method:</code></p>
<p><code><code>class User &lt; ActiveRecord::Base<br />
has_and_belongs_to_many :groups # foreign keys in the join table</code></p>
<p><code> def join_group(group)<br />
groups.push_with_attributes(group, :joined_at =&gt; Time.now)<br />
end<br />
end</code></p>
<li>The second way uses a has_many association with the :through option and a join model:<br />
<code>class Subscriptions &lt; ActiveRecord::Base<br />
belongs_to :group  # foreign key - programmer_id<br />
belongs_to :user     # foreign key - project_id<br />
end<br />
class Group  :subscriptions<br />
end<br />
class User  :subscriptions<br />
end<br />
</code></li>
<p></code></ol>
<p><code>If you have to work with the relationship model as its own entity, thent you'll need to use <span style="font-style: italic;">has_many :through</span>. Otherwise, you can just stick to <span style="font-style: italic;">has_and_belongs_to_many</span>.</p>
<p></code></p>
<div class="shr-publisher-45"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2007/02/10/hasandbelongstomany-or-hasmany-through/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating Rails Plugins</title>
		<link>http://neyric.com/2006/10/24/creating-rails-plugins/</link>
		<comments>http://neyric.com/2006/10/24/creating-rails-plugins/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 18:00:48 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://creating-rails-plugins</guid>
		<description><![CDATA[Just a link to &#8220;The Complete Guide to Rails Plugins&#8221; which is a reference.]]></description>
			<content:encoded><![CDATA[<p>Just a link to <a href="http://nubyonrails.com/articles/2006/05/04/the-complete-guide-to-rails-plugins-part-i">&#8220;The Complete Guide to Rails Plugins&#8221;</a> which is a reference.</p>
<div class="shr-publisher-33"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2006/10/24/creating-rails-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visualize your models</title>
		<link>http://neyric.com/2006/10/24/visualize-your-models/</link>
		<comments>http://neyric.com/2006/10/24/visualize-your-models/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 17:43:16 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://visualize-your-models</guid>
		<description><![CDATA[The &#8220;Visualize Models&#8221; plugin By Nils Franzen will generate .png images from the Rails model files : (click to enlarge) : This plugin depends on GraphViz, which you can find here. From your rails application root, run : ruby script/plugin &#8230; <a href="http://neyric.com/2006/10/24/visualize-your-models/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://visualizemodels.rubyforge.org/">&#8220;Visualize Models&#8221; plugin</a> By Nils Franzen will generate .png images from the Rails model files :</p>
<p>(click to enlarge) :</p>
<p style="text-align: center"><a href="http://visualizemodels.rubyforge.org/typo2.png"><img src="http://visualizemodels.rubyforge.org/typo2.png" border="0" height="200" width="193" /></a></p>
<p>This plugin depends on GraphViz, which you can find <a href="http://www.graphviz.org/">here.</a></p>
<p>From your rails application root, run :</p>
<pre>ruby script/plugin install</pre>
<pre>svn://rubyforge.org//var/svn/visualizemodels/visualize_models</pre>
<pre>rake visualize_models</pre>
<p>You&#8217;ll then find your .png images in the &#8220;doc&#8221; directory.</p>
<div class="shr-publisher-31"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2006/10/24/visualize-your-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autocompletion with Rails and Scriptaculous</title>
		<link>http://neyric.com/2006/10/24/autocompletion-with-rails-and-scriptaculous/</link>
		<comments>http://neyric.com/2006/10/24/autocompletion-with-rails-and-scriptaculous/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 17:31:04 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[scriptaculous]]></category>

		<guid isPermaLink="false">http://autocompletion-with-rails-and-scriptaculous</guid>
		<description><![CDATA[Scriptaculous offers a nice autocompletion component that integrates quite well with Ruby on Rails.Here is a link that shows different ways to plug it in your rails application: http://www.slash7.com/articles/2005/08/13/ajaxariffic-au&#8230;]]></description>
			<content:encoded><![CDATA[<table>
<tbody>
<tr>
<td><img alt="Ruby On Rails" src="http://www.rubyonrails.org/images/rails.png" style="border: 0pt none"></td>
<td style="padding: 15px">
<p>Scriptaculous offers a nice autocompletion component that integrates quite well with Ruby on Rails.Here is a link that shows different ways to plug it in your rails application:</p>
<p><a href="http://www.slash7.com/articles/2005/08/13/ajaxariffic-autocomplete-with-scriptaculous">http://www.slash7.com/articles/2005/08/13/ajaxariffic-au&#8230;</a></td>
</tr>
</tbody>
</table>
<div class="shr-publisher-30"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2006/10/24/autocompletion-with-rails-and-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model validation with Rails</title>
		<link>http://neyric.com/2006/10/14/model-validation-with-rails/</link>
		<comments>http://neyric.com/2006/10/14/model-validation-with-rails/#comments</comments>
		<pubDate>Sat, 14 Oct 2006 19:56:47 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://model-validation-with-rails</guid>
		<description><![CDATA[Rails has very nice features to validate a model (directly mapped on your database). However it gets sometimes sloppy if you don&#8217;t know the exact command to do your validation.Here&#8217;s a trick I had a hard time to find. Everybody &#8230; <a href="http://neyric.com/2006/10/14/model-validation-with-rails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://www.rubyonrails.org/images/rails.png" alt="Ruby On Rails" /></td>
<td>Rails has very nice features to validate a model (directly mapped on your database). However it gets sometimes sloppy if you don&#8217;t know the exact command to do your validation.Here&#8217;s a trick I had a hard time to find.</td>
</tr>
</table>
<p>Everybody knows how to validate the uniqueness of a field in a database :</p>
<pre>validates_uniqueness_of :date</pre>
<p>If you now want to validate the uniqueness of a couple  (ex: date,user_id) here&#8217;s how you can:</p>
<pre>validates_uniqueness_of :date, :scope =&gt; :user_id</pre>
<div class="shr-publisher-24"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2006/10/14/model-validation-with-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails with Apache2 and FastCGI</title>
		<link>http://neyric.com/2005/07/04/ruby-on-rails-with-apache2-and-fastcgi/</link>
		<comments>http://neyric.com/2005/07/04/ruby-on-rails-with-apache2-and-fastcgi/#comments</comments>
		<pubDate>Mon, 04 Jul 2005 00:00:00 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[fcgi]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://ruby-on-rails-with-apache2-and-fastcgi</guid>
		<description><![CDATA[apt-get install ruby wget http://rubyforge.org/frs/download.php/3463/rubygems-0.8.8.tgz tar vxzf rubygems-0.8.8.tgz cd rubygems-0.8.8 ruby setup.rb gem update gem install rails]]></description>
			<content:encoded><![CDATA[<pre>apt-get install ruby</pre>
<pre>wget http://rubyforge.org/frs/download.php/3463/rubygems-0.8.8.tgz
tar vxzf rubygems-0.8.8.tgz
cd rubygems-0.8.8
ruby setup.rb</pre>
<pre>gem update
gem install rails</pre>
<div class="shr-publisher-32"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2005/07/04/ruby-on-rails-with-apache2-and-fastcgi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

