Instead of having it highlight the bad fields when you enter in a record
that fails validation, is there a way to make it do an action? I’m
looking for something like this:
if/else is much, much more performant than exception handling. You can
measure this yourself, write a little test program.
Also remember that rescue would “skip” any other code in-between the
raised exception and the rescue code, which may or may not be a bad
thing.
update_attributes and save are equivalent, I’d stick with
update_attributes
def update_attributes(attributes)
self.attributes = attributes
save
end
Daniel H. wrote:
Out of curiosity, why did you decide to use if/else instead of rescue?
And
why’d you use
@foo.attributes = params[:foo]
if @foo.save
instead of
if @foo.update_attributes(params[:foo])
which does the same thing?
Also, forgot to mention in my original email that redirecting the
browser is
the controller’s responsibility, not the model’s, which is why the
validation methods don’t allow you to specify what URL to go to when
validation fails.
Out of curiosity, why did you decide to use if/else instead of rescue?
And
why’d you use
@foo.attributes = params[:foo]
if @foo.save
instead of
if @foo.update_attributes(params[:foo])
which does the same thing?
Also, forgot to mention in my original email that redirecting the
browser is
the controller’s responsibility, not the model’s, which is why the
validation methods don’t allow you to specify what URL to go to when
validation fails.