On 8 Jul 2009, at 21:26, doug livesey wrote:

> Hi -- I'm using ActiveResource, and I want to be able, when a model  
> fails to create, to return the failure reason to the caller with the  
> 500 response.
> Can this be done?
> I'm currently calling :
>   render( :xml => { :error => model.errors.full_messages.join( " --  
> " ) }, :status => :internal_server_error } )


I've not used ActiveResource against it, but in my latest app I've got  
the following code:

>   def create
>     # Create the model
>     @model = Model.new(params[:model])
>     # Save eet!
>     @model.save!
>
>     respond_to do |format|
>       format.html { redirect_to model_url(@model) }
>       format.xml  { render :xml => @model, :status  
> => :created, :location => model_path(@model) }
>     end
>
>   rescue ActiveRecord::RecordInvalid
>     respond_to do |format|
>       format.html { render :action => "new", :status  
> => :unprocessable_entity }
>       format.xml  { render :xml => @model, :status  
> => :unprocessable_entity }
>     end
>   end

Also at http://pastie.textmate.org/539341

I think returning a 422 makes ActiveResource parse out the error hash  
from the model returned. But you shouldn't be returning  
an :internal_server_error for a model erroring anyway ;)

C
---
Caius Durling
[email protected]
+44 (0) 7960 268 100
http://caius.name/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nwrug-members?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to