To check if buyer.save is going to fail I use buyer.valid?:
def create
@buyer = Buyer.new(params[:buyer])
if @buyer.valid?
my_update_database_method
@buyer.save
else
...
end
end
How could I check if update_attributes is going to fail ?
def update
@buyer = Buyer.find(params[:id])
if <what should be here?>
my_update_database_method
@buyer.update_attributes(params[:buyer])
else
...
end
end
it returns false if it was not done, same with
save.save!will throw exceptions if you like that better. I’m not sure if there isupdate_attributes!, but it would be logical.just do
http://apidock.com/rails/ActiveRecord/Base/update_attributes
Edit
Then you want this method you have to write. If you want to pre check params sanitation.
Edit 2
Alternatively, depending on your constraints