<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Best practice RESTful queries in Rails</title>
	<atom:link href="http://www.mattcollins.net/2008/04/best-practice-restful-queries-in-rails/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mattcollins.net/2008/04/best-practice-restful-queries-in-rails</link>
	<description>Thoughts on Building Web Businesses</description>
	<lastBuildDate>Thu, 26 Jan 2012 01:56:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Buzzterrier</title>
		<link>http://www.mattcollins.net/2008/04/best-practice-restful-queries-in-rails/comment-page-1#comment-897</link>
		<dc:creator>Buzzterrier</dc:creator>
		<pubDate>Wed, 22 Oct 2008 19:08:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mulogy.com/blog/2008/04/best-practice-restful-queries-in-rails#comment-897</guid>
		<description>So how do your format &gt;, =, &lt;= queries?
/items?size=&gt;36
??</description>
		<content:encoded><![CDATA[<p>So how do your format &gt;, =, &lt;= queries?</p>
<p>/items?size=&gt;36</p>
<p>??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Jones</title>
		<link>http://www.mattcollins.net/2008/04/best-practice-restful-queries-in-rails/comment-page-1#comment-20</link>
		<dc:creator>Peter Jones</dc:creator>
		<pubDate>Mon, 21 Apr 2008 16:52:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mulogy.com/blog/2008/04/best-practice-restful-queries-in-rails#comment-20</guid>
		<description>By using an if statement in the controller, as detailed below, it is possible to move code to the model. This doesn&#039;t avoid sorting between the different cases in the controller, but it does make the code in the controller more readable and cuts down on the code there.
So linking to the specific querie using the following:
 &#039;great&#039;) %&gt;
will link to this url /items?average_rating=great which will access the following if statement in the items_controller:
  def index
  if params[:average_rating] == &quot;great&quot;
    @items = Item.find_items_that_are_great
  else
    @items = Item.find(:all)
...
  end
The else part of the statement returns RESTful results as expected from /items if the initial condition/querie is not met.
However, if the first condition of the if statement is met/true &quot;find_items_that_are_great&quot; in models/items.rb returns results  in accordance with the following which is the specific querie:
  def self.find_items_that_are_great
    find(:all, :order =&gt; &#039;score desc&#039;, :conditions =&gt; &#039;score&gt;4&#039; )
  end
The code is implemented here:
http://isitgreat.heroku.com/items?average_rating=great</description>
		<content:encoded><![CDATA[<p>By using an if statement in the controller, as detailed below, it is possible to move code to the model. This doesn&#8217;t avoid sorting between the different cases in the controller, but it does make the code in the controller more readable and cuts down on the code there.</p>
<p>So linking to the specific querie using the following:</p>
<p> &#8216;great&#8217;) %&gt;</p>
<p>will link to this url /items?average_rating=great which will access the following if statement in the items_controller:</p>
<p>  def index<br />
  if params[:average_rating] == &#8220;great&#8221;<br />
    @items = Item.find_items_that_are_great<br />
  else<br />
    @items = Item.find(:all)<br />
&#8230;<br />
  end</p>
<p>The else part of the statement returns RESTful results as expected from /items if the initial condition/querie is not met.</p>
<p>However, if the first condition of the if statement is met/true &#8220;find_items_that_are_great&#8221; in models/items.rb returns results  in accordance with the following which is the specific querie:</p>
<p>  def self.find_items_that_are_great<br />
    find(:all, :order =&gt; &#8216;score desc&#8217;, :conditions =&gt; &#8216;score&gt;4&#8242; )<br />
  end</p>
<p>The code is implemented here:</p>
<p><a href="http://isitgreat.heroku.com/items?average_rating=great" rel="nofollow">http://isitgreat.heroku.com/items?average_rating=great</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

