<?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"
	>
<channel>
	<title>Comments on: REST and Rails - no reason to be scared</title>
	<atom:link href="http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared/feed" rel="self" type="application/rss+xml" />
	<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared</link>
	<description>its a mirror - get it? Erik Kastner's blog.</description>
	<pubDate>Fri, 21 Nov 2008 13:45:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Derek</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-20542</link>
		<dc:creator>Derek</dc:creator>
		<pubDate>Fri, 24 Aug 2007 16:42:31 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-20542</guid>
		<description>@dhaval

Did you render the action or redirect?  If you redirect, you effectively refresh your instance variables, and your error object disappears.</description>
		<content:encoded><![CDATA[<p>@dhaval</p>
<p>Did you render the action or redirect?  If you redirect, you effectively refresh your instance variables, and your error object disappears.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dhaval</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-14075</link>
		<dc:creator>dhaval</dc:creator>
		<pubDate>Tue, 05 Jun 2007 08:40:26 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-14075</guid>
		<description>i still didnt get a error message after including error_message_for</description>
		<content:encoded><![CDATA[<p>i still didnt get a error message after including error_message_for</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: REST and Rails</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-5334</link>
		<dc:creator>REST and Rails</dc:creator>
		<pubDate>Fri, 26 Jan 2007 11:59:59 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-5334</guid>
		<description>[...] REST and Rails no reason to be scared [...]</description>
		<content:encoded><![CDATA[<p>[...] REST and Rails no reason to be scared [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Upperclass Twit : Refactoring to REST - Part 1.</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-3166</link>
		<dc:creator>The Upperclass Twit : Refactoring to REST - Part 1.</dc:creator>
		<pubDate>Sat, 23 Sep 2006 06:09:25 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-3166</guid>
		<description>[...] REST LINKS REST and Rails - no reason to be scared at Meta &#124; ateM [...]</description>
		<content:encoded><![CDATA[<p>[...] REST LINKS REST and Rails - no reason to be scared at Meta | ateM [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2930</link>
		<dc:creator>Derek</dc:creator>
		<pubDate>Fri, 15 Sep 2006 17:58:54 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2930</guid>
		<description>All right... So you use a GET request, passing the user_id in the URL as opposed to using POST.

Do you get a cleverly named URL for free in this case?  Something like message_url(@message, @user)</description>
		<content:encoded><![CDATA[<p>All right&#8230; So you use a GET request, passing the user_id in the URL as opposed to using POST.</p>
<p>Do you get a cleverly named URL for free in this case?  Something like message_url(@message, @user)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kastner</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2899</link>
		<dc:creator>Kastner</dc:creator>
		<pubDate>Thu, 14 Sep 2006 20:29:57 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2899</guid>
		<description>Derek - when you are nesting resources, GET /users/1/messages/3 will go to the messages controller, "show" action with params[:id] = 3 AND (here's the magic) params[:user_id] = 1

I'm still putzing around with map.resources :messages AND map.resources :users { &#124;user&#124; user.resources :messages }
which lets you do BOTH ways.</description>
		<content:encoded><![CDATA[<p>Derek - when you are nesting resources, GET /users/1/messages/3 will go to the messages controller, &#8220;show&#8221; action with params[:id] = 3 AND (here&#8217;s the magic) params[:user_id] = 1</p>
<p>I&#8217;m still putzing around with map.resources :messages AND map.resources :users { |user| user.resources :messages }<br />
which lets you do BOTH ways.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2896</link>
		<dc:creator>Derek</dc:creator>
		<pubDate>Thu, 14 Sep 2006 20:08:46 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2896</guid>
		<description>I'm interested in seeing some associations in action.

For one, I don't see the significance of: GET /users/1/messages/3
How is this not the same as: GET /messages/3

The simple cases look absolutely alluring.  Do associated REST URLs have the same beauty?</description>
		<content:encoded><![CDATA[<p>I&#8217;m interested in seeing some associations in action.</p>
<p>For one, I don&#8217;t see the significance of: GET /users/1/messages/3<br />
How is this not the same as: GET /messages/3</p>
<p>The simple cases look absolutely alluring.  Do associated REST URLs have the same beauty?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2460</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Sun, 20 Aug 2006 06:44:06 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2460</guid>
		<description>Don,

I just looked at the resource generatory Kastner mentioned and ripped two lines of code out of it &#38; dumped it into my controller (which is basically identical to the example you posted above). 

I used to handle my 'new' and 'edit' actions in the same function (called 'edit'). If an ID was passed in as a param, it would edit that ID, If no ID was passed in, it would create a new record. 

The 'save!' function throws an exception instead of returning 'false' like 'save' does...so we need to 'rescue' that exception. The new RESTful stuff breaks that logic, as you have obviously found out...

Here is my original code (generated from 'crud2_generator' with SLIGHT modifications):


  def create
    @person = Person.new(params[:person])
    
    @person.save!
    
    respond_to do &#124;format&#124;
      format.html do
        flash[:notice] = "#{@person.first_name} has been added to the database..."
        redirect_to :action =&#62; "index"
      end
      format.js   # Renders create.rjs
      format.xml do
        headers["Location"] = person_url(@person)
        render(:nothing =&#62; true, :status =&#62; "201 Created")
      end
    end
end


In order to get the error messages 'we have all grown to love' back, all you need to do is take this code &#38; throw it at the end of the function above:

rescue ActiveRecord::RecordInvalid
      render :action =&#62; 'new'
(*taken from: "tech's resource generator":http://svn.techno-weenie.net/projects/plugins/resource_generator/generators/resource/templates/controller.rb)

As long as you have the 'error_messages_for' call in you view...they should show up again now. 

I have not used this generator yet. I am currently using 'crud2_generator' to create my models/controllers, but adding these two lines of code took care of it for me. 

I hope that helps...</description>
		<content:encoded><![CDATA[<p>Don,</p>
<p>I just looked at the resource generatory Kastner mentioned and ripped two lines of code out of it &amp; dumped it into my controller (which is basically identical to the example you posted above). </p>
<p>I used to handle my &#8216;new&#8217; and &#8216;edit&#8217; actions in the same function (called &#8216;edit&#8217;). If an ID was passed in as a param, it would edit that ID, If no ID was passed in, it would create a new record. </p>
<p>The &#8217;save!&#8217; function throws an exception instead of returning &#8216;false&#8217; like &#8217;save&#8217; does&#8230;so we need to &#8216;rescue&#8217; that exception. The new RESTful stuff breaks that logic, as you have obviously found out&#8230;</p>
<p>Here is my original code (generated from &#8216;crud2_generator&#8217; with SLIGHT modifications):</p>
<p>  def create<br />
    @person = Person.new(params[:person])</p>
<p>    @person.save!</p>
<p>    respond_to do |format|<br />
      format.html do<br />
        flash[:notice] = &#8220;#{@person.first_name} has been added to the database&#8230;&#8221;<br />
        redirect_to :action =&gt; &#8220;index&#8221;<br />
      end<br />
      format.js   # Renders create.rjs<br />
      format.xml do<br />
        headers["Location"] = person_url(@person)<br />
        render(:nothing =&gt; true, :status =&gt; &#8220;201 Created&#8221;)<br />
      end<br />
    end<br />
end</p>
<p>In order to get the error messages &#8216;we have all grown to love&#8217; back, all you need to do is take this code &amp; throw it at the end of the function above:</p>
<p>rescue ActiveRecord::RecordInvalid<br />
      render :action =&gt; &#8216;new&#8217;<br />
(*taken from: &#8220;tech&#8217;s resource generator&#8221;:http://svn.techno-weenie.net/projects/plugins/resource_generator/generators/resource/templates/controller.rb)</p>
<p>As long as you have the &#8216;error_messages_for&#8217; call in you view&#8230;they should show up again now. </p>
<p>I have not used this generator yet. I am currently using &#8216;crud2_generator&#8217; to create my models/controllers, but adding these two lines of code took care of it for me. </p>
<p>I hope that helps&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kastner</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2421</link>
		<dc:creator>Kastner</dc:creator>
		<pubDate>Thu, 17 Aug 2006 23:25:57 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2421</guid>
		<description>Don, I don't have the answer for that, I'm still working on that myself. But Technoweenie's Restful resource generator handles the errors in a very slick, very rubyish way - it rescues AR errors.
Nice stuff.</description>
		<content:encoded><![CDATA[<p>Don, I don&#8217;t have the answer for that, I&#8217;m still working on that myself. But Technoweenie&#8217;s Restful resource generator handles the errors in a very slick, very rubyish way - it rescues AR errors.<br />
Nice stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Donald Piret</title>
		<link>http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2388</link>
		<dc:creator>Donald Piret</dc:creator>
		<pubDate>Wed, 16 Aug 2006 18:32:43 +0000</pubDate>
		<guid isPermaLink="false">http://metaatem.net/2006/07/31/rest-and-rails-no-reason-to-be-scared#comment-2388</guid>
		<description>This Restful stuff is nice and shiny, but where does all the validation and error handling go?


To cite some of your code:

# gets called when for POSTs to /people
  def create
    @person = Person.new(params[:person])
    @person.save!
    respond_to do &#124;format&#124;
      format.html do
        flash[:notice] = "Person was successfuly created"
        redirect_to person_url(@person)
      end
      format.js
    end
  end

In here I see that you're not dealing with the exception at all, are we just giving up the entire nice error handling functionality of Rails for extra restfullness, or am I missing something obvious?</description>
		<content:encoded><![CDATA[<p>This Restful stuff is nice and shiny, but where does all the validation and error handling go?</p>
<p>To cite some of your code:</p>
<p># gets called when for POSTs to /people<br />
  def create<br />
    @person = Person.new(params[:person])<br />
    @person.save!<br />
    respond_to do |format|<br />
      format.html do<br />
        flash[:notice] = &#8220;Person was successfuly created&#8221;<br />
        redirect_to person_url(@person)<br />
      end<br />
      format.js<br />
    end<br />
  end</p>
<p>In here I see that you&#8217;re not dealing with the exception at all, are we just giving up the entire nice error handling functionality of Rails for extra restfullness, or am I missing something obvious?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
