I notice that ActiveRecord::Base.update_attributes() calls save(). What if I want to get an exception if the save fails? Is there a way to get the update_attributes() function plus the save! function? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
> What if I want to get an exception if the save fails? Is there a way to > get the update_attributes() function plus the save! function? >Have you tried to raise an error based on the return value of the save? unless Something.update_attributes() raise "error message"
Wes Gamble wrote on 11.07.2006 02:24:> I notice that ActiveRecord::Base.update_attributes() calls save(). > > What if I want to get an exception if the save fails? Is there a way to > get the update_attributes() function plus the save! function?You could do raise Exception unless update_attributes() or attributes=() save!()
Or just define your own update_attributes! method in environment.rb:
class ActiveRecord::Base
def update_attributes!(attributes)
self.attributes = attributes
save!
end
end
-Jonathan.
On 7/11/06, Markus Kolb <usenet-072006@tower-net.de>
wrote:> Wes Gamble wrote on 11.07.2006 02:24:
> > I notice that ActiveRecord::Base.update_attributes() calls save().
> >
> > What if I want to get an exception if the save fails? Is there a way
to
> > get the update_attributes() function plus the save! function?
>
> You could do
>
> raise Exception unless update_attributes()
>
> or
>
> attributes=()
> save!()
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>