I have a model say "site" and another model "equipment". In the Site form I can attach equipment dynamically in the form and the equipment has attributes in the :through table. Is there a way to validate the equipment attributes ONLY when the SITE form has been completed?
anyone? On Jul 20, 7:42 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have amodelsay "site" and anothermodel"equipment". > > In the Site form I can attach equipment dynamically in the form and > the equipment has attributes in the :through table. > > Is there a way to validate the equipment attributes ONLY when the SITE > form has been completed?
You could use conditional validation. http://guides.rubyonrails.org/activerecord_validations_callbacks.html#using-a-symbol-with-if-and-unless That''s one way to do it. Cheers! Arzumy On Jul 22, 11:56 am, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> anyone? > > On Jul 20, 7:42 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have amodelsay "site" and anothermodel"equipment". > > > In the Site form I can attach equipment dynamically in the form and > > the equipment has attributes in the :through table. > > > Is there a way to validate the equipment attributes ONLY when the SITE > > form has been completed?
You can use nested forms (site has_one or has_many ''equipment'') http://railscasts.com/episodes/75-complex-forms-part-3 http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes erwin On 21 juil, 02:42, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a model say "site" and another model "equipment". > > In the Site form I can attach equipment dynamically in the form and > the equipment has attributes in the :through table. > > Is there a way to validate the equipment attributes ONLY when the SITE > form has been completed?
I would say that in your case the easy way is to not nest the forms. Just return in your post the list of equipments and the site. In your controller, save or update the site, then try to save each equipment. Make sure you reassign your instance variables properly. If you want to keep them nested and do this I would suggest submit the site the first time ''add equipment'' or whatever button is pressed and reload the page or AJAX it up in the background. -Josh On Jul 21, 11:38 pm, erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> You can use nested forms (site has_one or has_many ''equipment'') > > http://railscasts.com/episodes/75-complex-forms-part-3 > > http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nest... > > erwin > > On 21 juil, 02:42, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have a model say "site" and another model "equipment". > > > In the Site form I can attach equipment dynamically in the form and > > the equipment has attributes in the :through table. > > > Is there a way to validate the equipment attributes ONLY when the SITE > > form has been completed?
I do an ajax to add the equipment. The models are not nested. On Wed, Jul 22, 2009 at 3:40 AM, Josh <JoshBWhite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I would say that in your case the easy way is to not nest the forms. > Just return in your post the list of equipments and the site. In your > controller, save or update the site, then try to save each equipment. > Make sure you reassign your instance variables properly. > > If you want to keep them nested and do this I would suggest submit the > site the first time ''add equipment'' or whatever button is pressed and > reload the page or AJAX it up in the background. > > -Josh > > On Jul 21, 11:38 pm, erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > You can use nested forms (site has_one or has_many ''equipment'') > > > > http://railscasts.com/episodes/75-complex-forms-part-3 > > > > http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nest... > > > > erwin > > > > On 21 juil, 02:42, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I have a model say "site" and another model "equipment". > > > > > In the Site form I can attach equipment dynamically in the form and > > > the equipment has attributes in the :through table. > > > > > Is there a way to validate the equipment attributes ONLY when the SITE > > > form has been completed? > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---