How can I write a condition in a validation that will skip validation if it comes from a certain action? :if => don''t_validate_when_this_action Or how do you handle this, with validation, when you have an update form that are for updating certain fields/columns? -- 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 Jun 20, 8:34 am, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> How can I write a condition in a validation that will skip validation if > it comes from a certain action? > > :if => don''t_validate_when_this_action > > Or how do you handle this, with validation, when you have an update form > that are for updating certain fields/columns?The model has no idea what action has caused it to be validated. Either call save(false) which skips all validations, or let the model know (eg have an instance variable which indicates which validations can be skipped) Fred --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Jun 20, 8:34�am, P�l Bergstr�m <rails-mailing-l...@andreas-s.net> > wrote: >> How can I write a condition in a validation that will skip validation if >> it comes from a certain action? >> >> :if => don''t_validate_when_this_action >> >> Or how do you handle this, with validation, when you have an update form >> that are for updating certain fields/columns? > > The model has no idea what action has caused it to be validated. > Either call save(false) which skips all validations, or let the model > know (eg have an instance variable which indicates which validations > can be skipped) > > FredDo you mean save instead of update_attributes? How do I pick up that instance variable in the model? I can''t use params[:variable], right? Is it :variable? -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 20 Jun 2008, at 10:46, Pål Bergström wrote:> > Frederick Cheung wrote: >> On Jun 20, 8:34�am, P�l Bergstr�m <rails-mailing-l...@andreas- >> s.net> >> wrote: >>> How can I write a condition in a validation that will skip >>> validation if >>> it comes from a certain action? >>> >>> :if => don''t_validate_when_this_action >>> >>> Or how do you handle this, with validation, when you have an >>> update form >>> that are for updating certain fields/columns? >> >> The model has no idea what action has caused it to be validated. >> Either call save(false) which skips all validations, or let the model >> know (eg have an instance variable which indicates which validations >> can be skipped) >> >> Fred > > Do you mean save instead of update_attributes? > > How do I pick up that instance variable in the model? I can''t use > params[:variable], right? Is it :variable?not sure what you mean there. Fred --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 20 Jun 2008, at 10:46, Pål Bergström wrote: > >>>> >> >> Do you mean save instead of update_attributes? >> >> How do I pick up that instance variable in the model? I can''t use >> params[:variable], right? Is it :variable? > not sure what you mean there. > > FredNeither do I :-) I''ve been using Rails for a while now, but some stuff is still a bit confusing. Do you mean save as if I use a @object.save in the update action? -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
still a bit confusing.> > Do you mean save as if I use a @object.save in the update action?Is this the right way to write it? def update @object = Object.find(id) @object.update_attributes(params[:object]) @object.save(false) 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 20 Jun 2008, at 11:19, Pål Bergström wrote:> > still a bit confusing. >> >> Do you mean save as if I use a @object.save in the update action? > > Is this the right way to write it? > > def update > @object = Object.find(id) > @object.update_attributes(params[:object]) > @object.save(false)Not quite - update_attributes does the save for you, so this will save twice (although the update_attributes might fail because of the validation) @object = Object.find(id) @object.attributes = params[:object] @object.save(false) Should do the trick Fred> > 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?hl=en -~----------~----~----~----~------~----~------~--~---