I currently have:
if @message.save
@message.deliver_contact
flash[:success] = t('Your_message_successfully_sent')
redirect_to root_url
else
render :action => 'new'
end
In this code a message is first saved in the database and afterwards sent out (@message.deliver_contact). But, if the delivering fails, the record was already written away.
I want to reach that: * I only give the success flash if BOTH operations succeed (saving and sending) * if ONE operation fails, none of the operations should be executed (or the save should be rolled back).
I'm not experienced, anybody an idea how I should write that?