Hi all, After validation of a form field rails keeps the entered data in the form. The strange thing is that the entered data are kept in some fields but not in every field. Although the <td>-tags are almost the same. In the following form field the entered data is kept after the validation <td>Name:</td> <td><%=text_field("customer", "first_name")%></td> In the following the value is lost after validation <td>Strasse:</td> <td><%=text_field("contact_detail", "address1")%></td> Did anyone struggle over the same issue? -- 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 -~----------~----~----~----~------~----~------~--~---
On Oct 5, 1:07 pm, Yu Co <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> After validation of a form field rails keeps the entered data in the > form. The strange thing is that the entered data are kept in some fields > but not in every field. Although the <td>-tags are almost the same. In > the following form field the entered data is kept after the validation > <td>Name:</td> > <td><%=text_field("customer", "first_name")%></td> > > In the following the value is lost after validation > <td>Strasse:</td> > <td><%=text_field("contact_detail", "address1")%></td>Can you post your controller code? It looks like the @contact_detail object isn''t being populated. It''s probably something to do with the order that you''re assigning and validating things. Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear wrote:> On Oct 5, 1:07 pm, Yu Co <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> After validation of a form field rails keeps the entered data in the >> form. The strange thing is that the entered data are kept in some fields >> but not in every field. Although the <td>-tags are almost the same. In >> the following form field the entered data is kept after the validation >> <td>Name:</td> >> <td><%=text_field("customer", "first_name")%></td> >> >> In the following the value is lost after validation >> <td>Strasse:</td> >> <td><%=text_field("contact_detail", "address1")%></td> > > Can you post your controller code? It looks like the @contact_detail > object isn''t being populated. It''s probably something to do with the > order that you''re assigning and validating things. > > ChrisHi Chris, the relevant code piece of the corresponding controller looks like this: “ . . . def create @contact_detail = ContactDetail.new(params[:contact_detail]) @customer = Customer.new(params[:customer]) @customer.contact_detail = @contact_detail . . . if @customer.save . . session[''user''] = @customer session[:customer] = nil . . else begin session[:errors] = @errors end end … ” -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Yu Co wrote:> the relevant code piece of the corresponding controller looks like this: > > def create > @contact_detail = ContactDetail.new(params[:contact_detail]) > @customer = Customer.new(params[:customer]) > @customer.contact_detail = @contact_detail > > if @customer.save > session[''user''] = @customer > session[:customer] = nil > else > > begin > session[:errors] = @errors > end > endI can''t see how you''re redisplaying the form. Are you doing a render(:action => :new)? Are you redirecting back to the ''new'' action using redirect_to(:action => :new)? Or do you have a separate create.rhtml template? Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear wrote:> Yu Co wrote: >> else >> >> begin >> session[:errors] = @errors >> end >> end > > I can''t see how you''re redisplaying the form. Are you doing a > render(:action => :new)? Are you redirecting back to the ''new'' action > using redirect_to(:action => :new)? Or do you have a separate > create.rhtml template? > > Chrisaaa sorry for that. The relevant code piece looks like that: session[:errors] = @errors session[:customer] = @customer redirect_to :controller => ''auth'', :action => ''register'' and register.html: <%= start_form_tag :controller => ''customer'', :action => ''create'' %> <%= render :partial => ''customer/registrationform'' %> <tr><td colspan="2" align="center"><%= submit_tag "Register and Order" %></td></tr> <%= end_form_tag %> -- 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 -~----------~----~----~----~------~----~------~--~---
and the controller auth looks like this: def register @customer = session[:customer] == nil ? Customer.new : session[:customer] @errors = session[:errors] end I checked the values within ''register'' action. And indeed the entered data in the form is available under @customer.contact_detail. But after submitting the form the contact_detail dates are not shown but the customer dates. -- 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 -~----------~----~----~----~------~----~------~--~---
Yu Co wrote:> and the controller auth looks like this: > > def register > @customer = session[:customer] == nil ? Customer.new : > session[:customer] > @errors = session[:errors] > end > > > I checked the values within ''register'' action. And indeed the entered > data in the form is available under @customer.contact_detail. But after > submitting the form the contact_detail dates are not shown but the > customer dates.Your view is expecting to find the contact_detail object in @contact_detail, but you''re not setting this in the controller code. Try adding: @contact_detail = @customer.contact_detail to your register action. Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear wrote:> Yu Co wrote: >> data in the form is available under @customer.contact_detail. But after >> submitting the form the contact_detail dates are not shown but the >> customer dates. > > Your view is expecting to find the contact_detail object in > @contact_detail, but you''re not setting this in the controller code. > > Try adding: > > @contact_detail = @customer.contact_detail > > to your register action. > > ChrisHi Chris, many thanks to this advise. That’s the solution. I supposed that I need to change something in the controller and I thought that I even tried the suggestion you made. But that was apparently a mistake of mine :) . Thnx See ya -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---