Hi All, I have a nested form OUTER FORM for :doctor -- 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.
Hi All, I have a nested form OUTER FORM for :doctor INNER FORM for :user I am having problem is displaying the validation errors for both doctor and user model. Any idea about how I should be doing this. Thanks alot in advance. On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > I have a nested form > OUTER FORM for :doctor-- 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.
You can''t have a form inside of another one. Maybe I am misunderstanding? On Oct 12, 4:22 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > I have a nested form > OUTER FORM for :doctor > INNER FORM for :user > > I am having problem is displaying the validation errors for both > doctor and user model. Any idea about how I should be doing this. > > Thanks alot in advance. > > On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi All, > > I have a nested form > > OUTER FORM for :doctor-- 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.
I am pretty sure you have have nested forms....:) On Oct 12, 5:04 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote:> You can''t have a form inside of another one. Maybe I am > misunderstanding? > > On Oct 12, 4:22 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All, > > I have a nested form > > OUTER FORM for :doctor > > INNER FORM for :user > > > I am having problem is displaying the validation errors for both > > doctor and user model. Any idea about how I should be doing this. > > > Thanks alot in advance. > > > On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > I have a nested form > > > OUTER FORM for :doctor-- 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.
my nested form looks like <% form_for :doctor, :url => url do |doc_form| %> <table> <tr> <td> <%= doc_form.label :"Specialized Field: " %> </td> <td> <%= doc_form.text_field :specialize %> </td> </tr> <tr> <td> <%= doc_form.label :"Medical Center Name: " %> </td> <td> <%= doc_form.text_field :working_for %> </td> </tr> <% doc_form.fields_for :user, :url => url do |f| %> <tr> <td> <%= f.label :"First Name: " %> </td> <td> <%= f.text_field :fname %> </td> </tr> ..................... I want to display validation errors for both doctor and user...my create action in the controller looks like def create doc_attr = params[:doctor] user_attr = doc_attr.delete(:user) new_doctor = Doctor.new(doc_attr) new_doctor.user = User.new(user_attr) @saved = new_doctor.save! if @saved == true flash[:notice] = "Registration Successful" redirect_to login_path() else render :action => ''new'' end end Thank you On Oct 12, 5:04 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote:> You can''t have a form inside of another one. Maybe I am > misunderstanding? > > On Oct 12, 4:22 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All, > > I have a nested form > > OUTER FORM for :doctor > > INNER FORM for :user > > > I am having problem is displaying the validation errors for both > > doctor and user model. Any idea about how I should be doing this. > > > Thanks alot in advance. > > > On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > I have a nested form > > > OUTER FORM for :doctor-- 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.
Instead of having to manually create your child user at the controller- level, have a look at this: http://weblog.rubyonrails.org/2009/1/26/nested-model-forms And the API documentation is at: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html HTH On Oct 13, 7:57 am, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> my nested form looks like > > <% form_for :doctor, :url => url do |doc_form| %> > > <table> > <tr> > <td> <%= doc_form.label :"Specialized Field: " %> </td> > <td> <%= doc_form.text_field :specialize %> </td> > </tr> > <tr> > <td> <%= doc_form.label :"Medical Center Name: " %> </td> > <td> <%= doc_form.text_field :working_for %> </td> > </tr> > <% doc_form.fields_for :user, :url => url do |f| %> > > <tr> > <td> <%= f.label :"First Name: " %> </td> > <td> <%= f.text_field :fname %> </td> > </tr> > ..................... > I want to display validation errors for both doctor and user...my > create action in the controller looks like > > def create > doc_attr = params[:doctor] > user_attr = doc_attr.delete(:user) > new_doctor = Doctor.new(doc_attr) > new_doctor.user = User.new(user_attr) > @saved = new_doctor.save! > > if @saved == true > flash[:notice] = "Registration Successful" > redirect_to login_path() > else > render :action => ''new'' > end > end > > Thank you > > On Oct 12, 5:04 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote: > > > > > You can''t have a form inside of another one. Maybe I am > > misunderstanding? > > > On Oct 12, 4:22 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > I have a nested form > > > OUTER FORM for :doctor > > > INNER FORM for :user > > > > I am having problem is displaying the validation errors for both > > > doctor and user model. Any idea about how I should be doing this. > > > > Thanks alot in advance. > > > > On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All, > > > > I have a nested form > > > > OUTER FORM for :doctor-- 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.
radhames brito
2010-Oct-13 02:39 UTC
Re: Re: How to display validation errors in nested form
On Tue, Oct 12, 2010 at 5:04 PM, pepe <Pepe-gUAqH5+0sKL6V6G2DxALlg@public.gmane.org> wrote:> You can''t have a form inside of another one. Maybe I am > misunderstanding? > >you can have fields_for to nest a "form" for a child object -- 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.
I thought he meant he had 2 form tags, one inside of another. On Oct 12, 7:30 pm, binu <agarwal.bin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am pretty sure you have have nested forms....:) > > On Oct 12, 5:04 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote: > > > You can''t have a form inside of another one. Maybe I am > > misunderstanding? > > > On Oct 12, 4:22 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > I have a nested form > > > OUTER FORM for :doctor > > > INNER FORM for :user > > > > I am having problem is displaying the validation errors for both > > > doctor and user model. Any idea about how I should be doing this. > > > > Thanks alot in advance. > > > > On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All, > > > > I have a nested form > > > > OUTER FORM for :doctor-- 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.
I think you might be missing something in your models. In the Doctor model you should have: has_many :users accepts_nested_attributes_for :users In the User model you should have: belongs_to :doctor I think I''ve run into the same problem before and it was due to the fact that I was missing the ''accepts_nested_attributes_for''. On Oct 12, 7:57 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> my nested form looks like > > <% form_for :doctor, :url => url do |doc_form| %> > > <table> > <tr> > <td> <%= doc_form.label :"Specialized Field: " %> </td> > <td> <%= doc_form.text_field :specialize %> </td> > </tr> > <tr> > <td> <%= doc_form.label :"Medical Center Name: " %> </td> > <td> <%= doc_form.text_field :working_for %> </td> > </tr> > <% doc_form.fields_for :user, :url => url do |f| %> > > <tr> > <td> <%= f.label :"First Name: " %> </td> > <td> <%= f.text_field :fname %> </td> > </tr> > ..................... > I want to display validation errors for both doctor and user...my > create action in the controller looks like > > def create > doc_attr = params[:doctor] > user_attr = doc_attr.delete(:user) > new_doctor = Doctor.new(doc_attr) > new_doctor.user = User.new(user_attr) > @saved = new_doctor.save! > > if @saved == true > flash[:notice] = "Registration Successful" > redirect_to login_path() > else > render :action => ''new'' > end > end > > Thank you > > On Oct 12, 5:04 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote: > > > You can''t have a form inside of another one. Maybe I am > > misunderstanding? > > > On Oct 12, 4:22 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi All, > > > I have a nested form > > > OUTER FORM for :doctor > > > INNER FORM for :user > > > > I am having problem is displaying the validation errors for both > > > doctor and user model. Any idea about how I should be doing this. > > > > Thanks alot in advance. > > > > On Oct 12, 4:16 pm, Dean <deansam2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi All, > > > > I have a nested form > > > > OUTER FORM for :doctor-- 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.