[LRUG] [Chat] IronRuby
Jonathan Leighton
j at jonathanleighton.com
Tue Jul 24 08:00:22 PDT 2007
On Tue, 2007-07-24 at 14:53 +0100, James Adam wrote:
> On 7/24/07, Pratik Naik <pratik at thinkwares.com> wrote:
> > def create
> > @person = Person.new(params[:person])
> > @person.save!
> > redirect_to :index
> > rescue ActiveRecord::RecordInvalid
> > render :action => 'new'
> > end
>
> Why is that better than
>
> def create
> @person = Person.new(params[:person])
> if @person.save
> redirect_to :index
> else
> render :action => "new"
> end
> end
>
> ?
Whether or not using an exception is better than using a conditional, if
you use an exception you can define a rescue_action in your
ApplicationController which allows you to generalise validation handling
across the entire application. From experience, that's really damn
useful (and less code etc bla bla bla).
More information about the Chat
mailing list