Rich P.
2009-Nov-15 12:13 UTC
Problem creating Email form with redirect back if there are errors
Newbie here. I''m trying to create a simple e-mail form that validates if the name & email have been entered, and if not, sends the user back to the form with the previously entered data. The problem is I''m losing the form parameters (param[:name], param[:address], param [:message]), which means the user will have to re-enter them. What am I not understanding? def deliver_email @errors = [] if params[:name].empty? @errors << "Enter your name" end if params[:address].empty? @errors << "Enter your e-mail address" end unless @errors.empty? flash[:notice] = @errors redirect_to (:action => ''compose_email'', :id => params[:id]) end (send the email...) end
Darian Shimy
2009-Nov-15 17:21 UTC
Re: Problem creating Email form with redirect back if there are errors
So there are a few ways to do this, but since you are a newbie, it might be best to use a model, rather than parameters ("Rails way" vs. "You could do it like that"). To fully diagnose this issue, I need to see the view. My guess is that you are not including the params in the view to populate the form. Darian Shimy -- http:/www.darianshimy.com http://twitter.com/dshimy On Sun, Nov 15, 2009 at 4:13 AM, Rich P. <rich.pav-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Newbie here. I''m trying to create a simple e-mail form that validates > if the name & email have been entered, and if not, sends the user back > to the form with the previously entered data. The problem is I''m > losing the form parameters (param[:name], param[:address], param > [:message]), which means the user will have to re-enter them. What am > I not understanding? > > def deliver_email > @errors = [] > if params[:name].empty? > @errors << "Enter your name" > end > if params[:address].empty? > @errors << "Enter your e-mail address" > end > unless @errors.empty? > flash[:notice] = @errors > redirect_to (:action => ''compose_email'', :id => params[:id]) > end > (send the email...) > end > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---