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:
So i have
@user.get_confirmation # To populate the confirmation fields.
if @user.save
@user.send_confirmation
else
...
end
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:
@user.get_confirmation
if @user_save_test
if @user.send_confirmation
@user.save
end
end
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 1, 2010 at 7:53 PM, Álvaro Morais <alvarommorais-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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: > > So i have > > @user.get_confirmation # To populate the confirmation fields. > if @user.save > -QDnFQlcmCNdgoHlPtYpdqQ@public.gmane.org_confirmation > else > ... > end > > 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: > > @user.get_confirmation > if @user_save_test > if @user.send_confirmation > @user.save > end > end >You should use a before_save callback in your model. Something like this: Class User def before_save self.send_confirmation if self.valid? end end Also, you should take a look at: http://guides.rubyonrails.org/activerecord_validations_callbacks.html Hope it helps. Cheers. -- Leonardo Mateo. There''s no place like ~ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes it helps. Thank you. Love your sig. On Jan 2, 11:06 am, Leonardo Mateo <leonardoma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Jan 1, 2010 at 7:53 PM, Álvaro Morais <alvarommor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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: > > > So i have > > > @user.get_confirmation # To populate the confirmation fields. > > if @user.save > > -QDnFQlcmCNdgoHlPtYpdqQ@public.gmane.org_confirmation > > else > > ... > > end > > > 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: > > > @user.get_confirmation > > if @user_save_test > > if @user.send_confirmation > > @user.save > > end > > end > > You should use a before_save callback in your model. > Something like this: > > Class User > def before_save > self.send_confirmation if self.valid? > end > end > > Also, you should take a look at:http://guides.rubyonrails.org/activerecord_validations_callbacks.html > > Hope it helps. > > Cheers. > -- > Leonardo Mateo. > There''s no place like ~-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.