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
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
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 G. 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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs