Test for field validation before saving

Hi. I'm new to rails, and I must say I'm loving it.
I have a question that some of you may already found the answer.

Here's the problem
I've made a simple user signup interface that sends a confirmation
link to the email of the link.
The problem is that I want to confirm if everything is ok before
saving including the sending of the confirmation email.


So i have

@user.get_confirmation # To populate the confirmation fields.
if @user.save

The problem is that @user is saved before the confirmation is sent so
my only option is to display a message that there was a problem with
the confirmation email, and delete the record after.

Is there a method like @user.save_test
so that I can make something like this:

if @user_save_test
   if @user.send_confirmation

Thanks in advance.

You should use a before_save callback in your model.
Something like this:

Class User
  def before_save
    self.send_confirmation if self.valid?

Also, you should take a look at:

Hope it helps.


Yes it helps. Thank you.
Love your sig.