If I have a site model that has_many :equipments, how would I validate the equipment only when ceratin conditions exist in the site model? I add the equipment dynamically in the Site form and also the form will not necessarily be "fully submitted" until some conditions exist in the main site form.
This maybe of some help: http://railscasts.com/episodes/41-conditional-validations Cheers, Nicholas On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If I have a site model that has_many :equipments, how would I validate > the equipment only when ceratin conditions exist in the site model? > > I add the equipment dynamically in the Site form and also the form > will not necessarily be "fully submitted" until some conditions exist > in the main site form.
Well sort of. I really need to validate another model based on the original form(model) conditions. On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry <nicholas.henry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > This maybe of some help: > > http://railscasts.com/episodes/41-conditional-validations > > Cheers, > Nicholas > > On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > If I have a site model that has_many :equipments, how would I validate > > the equipment only when ceratin conditions exist in the site model? > > > > I add the equipment dynamically in the Site form and also the form > > will not necessarily be "fully submitted" until some conditions exist > > in the main site form. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Well sort of. I really need to validate another model based on the original > form(model) conditions.Do you mean you are trying to validate a model that has already been written to the database, when a form for a different model is submitted? If not I think a little more detail in exactly what you are trying to do may help. Colin> > On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry <nicholas.henry-Re5JQEeQqe8@public.gmane.orgm> > wrote: >> >> This maybe of some help: >> >> http://railscasts.com/episodes/41-conditional-validations >> >> Cheers, >> Nicholas >> >> On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > If I have a site model that has_many :equipments, how would I validate >> > the equipment only when ceratin conditions exist in the site model? >> > >> > I add the equipment dynamically in the Site form and also the form >> > will not necessarily be "fully submitted" until some conditions exist >> > in the main site form. >> > > > > >
Yes, Site is the main model, equipment is associated. I only want to validate the equipment model when conditions exist in the site model. On Wed, Jul 29, 2009 at 4:48 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > Well sort of. I really need to validate another model based on the > original > > form(model) conditions. > > Do you mean you are trying to validate a model that has already been > written to the database, when a form for a different model is > submitted? If not I think a little more detail in exactly what you > are trying to do may help. > > Colin > > > > > > On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry < > nicholas.henry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> > >> This maybe of some help: > >> > >> http://railscasts.com/episodes/41-conditional-validations > >> > >> Cheers, > >> Nicholas > >> > >> On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > If I have a site model that has_many :equipments, how would I validate > >> > the equipment only when ceratin conditions exist in the site model? > >> > > >> > I add the equipment dynamically in the Site form and also the form > >> > will not necessarily be "fully submitted" until some conditions exist > >> > in the main site form. > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Yes, Site is the main model, equipment is associated. I only want to > validate the equipment model when conditions exist in the site model.Is that ''yes'' in response to '' Do you mean you are trying to validate a model that has already been written to the database''? If so then that does not make sense. Validation is about checking that data is correct before allowing it to be written to the db. If it is already in the db it is too late to validate it. Colin> > On Wed, Jul 29, 2009 at 4:48 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> > Well sort of. I really need to validate another model based on the >> > original >> > form(model) conditions. >> >> Do you mean you are trying to validate a model that has already been >> written to the database, when a form for a different model is >> submitted? If not I think a little more detail in exactly what you >> are trying to do may help. >> >> Colin >> >> >> > >> > On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry >> > <nicholas.henry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > wrote: >> >> >> >> This maybe of some help: >> >> >> >> http://railscasts.com/episodes/41-conditional-validations >> >> >> >> Cheers, >> >> Nicholas >> >> >> >> On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > If I have a site model that has_many :equipments, how would I >> >> > validate >> >> > the equipment only when ceratin conditions exist in the site model? >> >> > >> >> > I add the equipment dynamically in the Site form and also the form >> >> > will not necessarily be "fully submitted" until some conditions exist >> >> > in the main site form. >> >> >> > >> > >> > > >> > >> >> > > > > >
Well it may not seem like it does not make sense but in the context of this app it does with the what the form is supposed . This is our flow. 1. Site is installed with eqpt. 2. The person using the form puts all eqpt that is on site attached to the form dynamically. 3. I have fields for the eqpt showing that it is installed correctly, settings are correct , .... 4. You can add eqpt but is might not necessarily be installed correctly, have issues, blah.... Step 4 is the reason that the form may be "submitted" but not fully processed until the issues at a site get resolved. On Wed, Jul 29, 2009 at 11:29 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > Yes, Site is the main model, equipment is associated. I only want to > > validate the equipment model when conditions exist in the site model. > > Is that ''yes'' in response to '' Do you mean you are trying to validate > a model that has already been written to the database''? If so then > that does not make sense. Validation is about checking that data is > correct before allowing it to be written to the db. If it is already > in the db it is too late to validate it. > > Colin > > > > > On Wed, Jul 29, 2009 at 4:48 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >> > >> 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > >> > Well sort of. I really need to validate another model based on the > >> > original > >> > form(model) conditions. > >> > >> Do you mean you are trying to validate a model that has already been > >> written to the database, when a form for a different model is > >> submitted? If not I think a little more detail in exactly what you > >> are trying to do may help. > >> > >> Colin > >> > >> > >> > > >> > On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry > >> > <nicholas.henry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> > wrote: > >> >> > >> >> This maybe of some help: > >> >> > >> >> http://railscasts.com/episodes/41-conditional-validations > >> >> > >> >> Cheers, > >> >> Nicholas > >> >> > >> >> On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> > If I have a site model that has_many :equipments, how would I > >> >> > validate > >> >> > the equipment only when ceratin conditions exist in the site model? > >> >> > > >> >> > I add the equipment dynamically in the Site form and also the form > >> >> > will not necessarily be "fully submitted" until some conditions > exist > >> >> > in the main site form. > >> >> > >> > > >> > > >> > > > >> > > >> > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Well it may not seem like it does not make sense but in the context of this > app it does with the what the form is supposed .Pardon?> This is our flow. > 1. Site is installed with eqpt. > 2. The person using the form puts all eqpt that is on site attached to the > form dynamically. > 3. I have fields for the eqpt showing that it is installed correctly, > settings are correct , .... > 4. You can add eqpt but is might not necessarily be installed correctly, > have issues, blah.... > Step 4 is the reason that the form may be "submitted" but not fully > processed until the issues at a site get resolved.No, sorry, I am completely flummoxed now, I have no idea what you are trying to do. You are not explaining the problem in terms that I understand, which may well be my fault. Colin> > On Wed, Jul 29, 2009 at 11:29 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> > Yes, Site is the main model, equipment is associated. I only want to >> > validate the equipment model when conditions exist in the site model. >> >> Is that ''yes'' in response to '' Do you mean you are trying to validate >> a model that has already been written to the database''? If so then >> that does not make sense. Validation is about checking that data is >> correct before allowing it to be written to the db. If it is already >> in the db it is too late to validate it. >> >> Colin >> >> > >> > On Wed, Jul 29, 2009 at 4:48 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> >> > wrote: >> >> >> >> 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> >> > Well sort of. I really need to validate another model based on the >> >> > original >> >> > form(model) conditions. >> >> >> >> Do you mean you are trying to validate a model that has already been >> >> written to the database, when a form for a different model is >> >> submitted? If not I think a little more detail in exactly what you >> >> are trying to do may help. >> >> >> >> Colin >> >> >> >> >> >> > >> >> > On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry >> >> > <nicholas.henry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >> > wrote: >> >> >> >> >> >> This maybe of some help: >> >> >> >> >> >> http://railscasts.com/episodes/41-conditional-validations >> >> >> >> >> >> Cheers, >> >> >> Nicholas >> >> >> >> >> >> On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> > If I have a site model that has_many :equipments, how would I >> >> >> > validate >> >> >> > the equipment only when ceratin conditions exist in the site >> >> >> > model? >> >> >> > >> >> >> > I add the equipment dynamically in the Site form and also the form >> >> >> > will not necessarily be "fully submitted" until some conditions >> >> >> > exist >> >> >> > in the main site form. >> >> >> >> >> > >> >> > >> >> > > >> >> > >> >> >> >> >> > >> > >> > > >> > >> >> > > > > >
I have the main form "Site", has many :equipments. In the Site form I add equipment to the form dynamically to associate it to the site. I do not necessarily need to validate the equipment fields on the form submission unless a checkbox is checked on the "Site" form stating everything is good. Basically I only need to validate the equipment under specific case on the site model. On Wed, Jul 29, 2009 at 2:37 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > Well it may not seem like it does not make sense but in the context of > this > > app it does with the what the form is supposed . > > Pardon? > > > This is our flow. > > 1. Site is installed with eqpt. > > 2. The person using the form puts all eqpt that is on site attached to > the > > form dynamically. > > 3. I have fields for the eqpt showing that it is installed correctly, > > settings are correct , .... > > 4. You can add eqpt but is might not necessarily be installed correctly, > > have issues, blah.... > > Step 4 is the reason that the form may be "submitted" but not fully > > processed until the issues at a site get resolved. > > No, sorry, I am completely flummoxed now, I have no idea what you are > trying to do. You are not explaining the problem in terms that I > understand, which may well be my fault. > > Colin > > > > > On Wed, Jul 29, 2009 at 11:29 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >> > >> 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > >> > Yes, Site is the main model, equipment is associated. I only want to > >> > validate the equipment model when conditions exist in the site model. > >> > >> Is that ''yes'' in response to '' Do you mean you are trying to validate > >> a model that has already been written to the database''? If so then > >> that does not make sense. Validation is about checking that data is > >> correct before allowing it to be written to the db. If it is already > >> in the db it is too late to validate it. > >> > >> Colin > >> > >> > > >> > On Wed, Jul 29, 2009 at 4:48 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > >> > wrote: > >> >> > >> >> 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > >> >> > Well sort of. I really need to validate another model based on the > >> >> > original > >> >> > form(model) conditions. > >> >> > >> >> Do you mean you are trying to validate a model that has already been > >> >> written to the database, when a form for a different model is > >> >> submitted? If not I think a little more detail in exactly what you > >> >> are trying to do may help. > >> >> > >> >> Colin > >> >> > >> >> > >> >> > > >> >> > On Tue, Jul 28, 2009 at 10:25 PM, Nicholas Henry > >> >> > <nicholas.henry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> >> > wrote: > >> >> >> > >> >> >> This maybe of some help: > >> >> >> > >> >> >> http://railscasts.com/episodes/41-conditional-validations > >> >> >> > >> >> >> Cheers, > >> >> >> Nicholas > >> >> >> > >> >> >> On Jul 28, 10:15 pm, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> > If I have a site model that has_many :equipments, how would I > >> >> >> > validate > >> >> >> > the equipment only when ceratin conditions exist in the site > >> >> >> > model? > >> >> >> > > >> >> >> > I add the equipment dynamically in the Site form and also the > form > >> >> >> > will not necessarily be "fully submitted" until some conditions > >> >> >> > exist > >> >> >> > in the main site form. > >> >> >> > >> >> > > >> >> > > >> >> > > > >> >> > > >> >> > >> >> > >> > > >> > > >> > > > >> > > >> > >> > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> I have the main form "Site", has many :equipments. > In the Site form I add equipment to the form dynamically to associate it to > the site. > I do not necessarily need to validate the equipment fields on the form > submission unless a checkbox is checked on the "Site" form stating > everything is good. > Basically I only need to validate the equipment under specific case on the > site model. >So, is this it? A user has entered data for an Equipment record onto the form and submitted it, you have some validations defined but you only want to run them if the associated site record (in the db) has a particular flag set? If the flag in the db is not set then you want to save the Equipment record without validating? Colin
Ya, now that you said a flag would be good. I was initially referring to the main Site model initiating the validation for the equipment but a flag in the equipment model would probably be an easier solution. On Wed, Jul 29, 2009 at 2:53 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 2009/7/29 Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > I have the main form "Site", has many :equipments. > > In the Site form I add equipment to the form dynamically to associate it > to > > the site. > > I do not necessarily need to validate the equipment fields on the form > > submission unless a checkbox is checked on the "Site" form stating > > everything is good. > > Basically I only need to validate the equipment under specific case on > the > > site model. > > > > So, is this it? A user has entered data for an Equipment record onto > the form and submitted it, you have some validations defined but you > only want to run them if the associated site record (in the db) has a > particular flag set? If the flag in the db is not set then you want > to save the Equipment record without validating? > > Colin > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello Chris: There''s also an :if option for the validates_associated class method: ":if - Specifies a method, proc or string to call to determine if the validation should occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The method, proc or string should return or evaluate to a true or false value." http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates_associated Cheers, Nicholas On Jul 29, 4:09 pm, Chris Habgood <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ya, now that you said a flag would be good. I was initially referring to > the main Site model initiating the validation for the equipment but a flag > in the equipment model would probably be an easier solution. > > > > On Wed, Jul 29, 2009 at 2:53 PM, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > 2009/7/29 Chris Habgood <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > I have the main form "Site", has many :equipments. > > > In the Site form I add equipment to the form dynamically to associate it > > to > > > the site. > > > I do not necessarily need to validate the equipment fields on the form > > > submission unless a checkbox is checked on the "Site" form stating > > > everything is good. > > > Basically I only need to validate the equipment under specific case on > > the > > > site model. > > > So, is this it? A user has entered data for an Equipment record onto > > the form and submitted it, you have some validations defined but you > > only want to run them if the associated site record (in the db) has a > > particular flag set? If the flag in the db is not set then you want > > to save the Equipment record without validating? > > > Colin
I think from your description you don''t really want ''validations'' in the rails sense. You might want to look into using some sort of state machine and do some conditions checking of the interrelated models when the main model is saved. On Wed, Jul 29, 2009 at 1:09 PM, Chris Habgood <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ya, now that you said a flag would be good. I was initially referring to > the main Site model initiating the validation for the equipment but a flag > in the equipment model would probably be an easier solution.-- Cynthia Kiser cynthia.kiser-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---