Hi, In my form I have about 10 fields and after validating them, I need to show all the validation errors. But <% if @flash[:error] %> <%= @flash[:error] %> <% end %> is showing only the last error being put in the flash. How can I show multiple errors using flash or otherwise ? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 1/28/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > In my form I have about 10 fields and after validating them, I need to > show all the validation errors. But > > <% if @flash[:error] %> > <%= @flash[:error] %> > <% end %> > > is showing only the last error being put in the flash. > > How can I show multiple errors using flash or otherwise ? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > > >If these are errors from your models you can use error_messages_for(...) <%= error_messages_for :user %> Hope this helps. -- Zack Chandler http://depixelate.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
no, these error are not from models but are from actions. Zack Chandler wrote:> On 1/28/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> is showing only the last error being put in the flash. >> >> How can I show multiple errors using flash or otherwise ? >> >> Thanks. >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > If these are errors from your models you can use error_messages_for(...) > > <%= error_messages_for :user %> > > Hope this helps. > > -- > Zack Chandler > http://depixelate.com-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 1/28/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > no, these error are not from models but are from actions. > > > > Zack Chandler wrote: > > On 1/28/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> is showing only the last error being put in the flash. > >> > >> How can I show multiple errors using flash or otherwise ? > >> > >> Thanks. > >> > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > If these are errors from your models you can use error_messages_for(...) > > > > <%= error_messages_for :user %> > > > > Hope this helps. > > > > -- > > Zack Chandler > > http://depixelate.com > > > -- > Posted via http://www.ruby-forum.com/. > > > >I can''t think of an example of when you''d have multiple errors when not dealing with models. Are you sure you''re not talking about errors in saving, creating, or modifying ActiveRecord models? Give an example of 10 errors. -- Zack Chandler http://depixelate.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fields on the form will be added to different tables in database after validation. Like used details will go to user table, address will go to address table and so on. I am new to RoR , hence may be I am not able to explain excatly in terms of models and views. Thanks for the help. Zack Chandler wrote:> On 1/28/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> >> > <%= error_messages_for :user %> >> >> > >> > > I can''t think of an example of when you''d have multiple errors when > not dealing with models. Are you sure you''re not talking about errors > in saving, creating, or modifying ActiveRecord models? Give an > example of 10 errors. > > -- > Zack Chandler > http://depixelate.com-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think the problem is that you''re assigning multiple errors to flash[:error] like this: flash[:error] = "whatever" and that will clobber all your old assignments. If this is the case, you can just do this at the beginning of your controller method: flash[:error] = [] and then push error messages into the Array. You could use a hash if you wanted that functionality. There''s a couple of different ways to do that but the important thing is to remember that while flash is a hash, flash[:whatever] isn''t [unless you make it so]. Then again, this might not be the problem but since you didn''t post any code I''m having to assume it is. RSL On 1/29/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Fields on the form will be added to different tables in database after > validation. > Like used details will go to user table, address will go to address > table and so on. I am new to RoR , hence may be I am not able to explain > excatly in terms of models and views. > > Thanks for the help. > > Zack Chandler wrote: > > On 1/28/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> > >> > <%= error_messages_for :user %> > >> > >> > > >> > > > > I can''t think of an example of when you''d have multiple errors when > > not dealing with models. Are you sure you''re not talking about errors > > in saving, creating, or modifying ActiveRecord models? Give an > > example of 10 errors. > > > > -- > > Zack Chandler > > http://depixelate.com > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I am still stuck on this problem. I will explain what I am trying to do: On my form I have fields to creae a new user. For that I have a login id, pwd1 and pwd2 and email fields alongwith other fields. Now if login already exists, or two passwords don''t match or email is not in a corret in proper format, then I need to show all the error alongwith the values entered by the user. I am able to show only the last error put in flash[:error] as: flash[:error] = msg All the error that I have put in before are not displayed in the view by : <% if flash[:error] -%> <%= flash[:error]%> <% flash[:error] = nil %> <%else %> <% end -%> Also how can I fill the form with the values entered by the user when view is displayed again ? I am new to ruby and rails, hence this seems like a big task for me. Any help is really appreciated. Russell Norris wrote:> I think the problem is that you''re assigning multiple errors to > flash[:error] like this: > > flash[:error] = "whatever" > > and that will clobber all your old assignments. If this is the case, you > can > just do this at the beginning of your controller method: > > flash[:error] = [] > > and then push error messages into the Array. You could use a hash if you > wanted that functionality. There''s a couple of different ways to do that > but > the important thing is to remember that while flash is a hash, > flash[:whatever] isn''t [unless you make it so]. > > Then again, this might not be the problem but since you didn''t post any > code > I''m having to assume it is. > > RSL-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2/1/07, Rm Rm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I am still stuck on this problem. I will explain what I am trying to do: > > On my form I have fields to creae a new user. For that I have a login > id, pwd1 and pwd2 and email fields alongwith other fields. Now if login > already exists, or two passwords don''t match or email is not in a corret > in proper format, then I need to show all the error alongwith the values > entered by the user. I am able to show only the last error put in > flash[:error] as:It sounds like you''d benefit from reviewing the basics of creating models (a new user in this case) from forms. I highly recommend the AWDWR book for this. But to get you jumpstarted you can use the following code as an example: <%= error_messages_for :user %> <% form_tag :action => ''create'' do %> Username: <%= text_field :user, :name %> </br> Password: <%= password_field :user, :password %> </br> Password: <%= password_field :user, :password_confirmation %> </br> Email: <%= text_field :user, :email_address %> </br> <%= submit_tag ''Create user'' %> <% end %>> > flash[:error] = msg > > All the error that I have put in before are not displayed in the view by > : > <% if flash[:error] -%> > <%= flash[:error]%> > <% flash[:error] = nil %> > <%else %> > > <% end -%> > > Also how can I fill the form with the values entered by the user when > view is displayed again ? I am new to ruby and rails, hence this seems > like a big task for me. Any help is really appreciated.In your controller''s action: def create @user = User.create(params[:user]) if @user.valid? flash[:success] = ''User created.'' redirect_to :action => ''index'' else render :action => ''new'' end end This will preserves the form values. Hope this helps. -- Zack Chandler http://depixelate.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---