I have a form which is used to update multiple records (of the same model) at one time, which it successfully does, but when I try to add vaildation to the form, it seems to be ignored. Code from the update method of my controller: def update SurvCamera.transaction do SurvCamera.update(params[:surv_camera].keys, params[:surv_camera].values ) end flash[:notice] = "Cameras successfully updated." redirect_to :action => ''show'', :id => params[:id] rescue ActiveRecord::RecordInvalid render :action => ''edit'' end In the model, I have the following to validate that "location" field is not empty: validates_presence_of :location Like I mentioned...the updates work fine, however when I try to edit records and leave location empty, it still attempts to save the record w/out first running validation. Any suggestions? -- 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-/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.
On 16 December 2010 15:53, Brian Penrose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a form which is used to update multiple records (of the same > model) at one time, which it successfully does, but when I try to add > vaildation to the form, it seems to be ignored. > > Code from the update method of my controller: > > def update > SurvCamera.transaction do > SurvCamera.update(params[:surv_camera].keys, > params[:surv_camera].values ) > end > flash[:notice] = "Cameras successfully updated." > redirect_to :action => ''show'', :id => params[:id] > > rescue ActiveRecord::RecordInvalid > render :action => ''edit'' > end > > In the model, I have the following to validate that "location" field is > not empty: > > validates_presence_of :location > > Like I mentioned...the updates work fine, however when I try to edit > records and leave location empty, it still attempts to save the record > w/out first running validation. Any suggestions?What do you mean by ''attempts to save w/out first running validations''? Do you mean you get an exception, or do you mean it saves with invalid data, or do you mean it does not save the invalid record but does not tell you that it has failed, or do you mean something else? 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-/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.
Colin Law wrote in post #968879:> On 16 December 2010 15:53, Brian Penrose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> end >> validates_presence_of :location >> >> Like I mentioned...the updates work fine, however when I try to edit >> records and leave location empty, it still attempts to save the record >> w/out first running validation. Any suggestions? > > What do you mean by ''attempts to save w/out first running > validations''? Do you mean you get an exception, or do you mean it > saves with invalid data, or do you mean it does not save the invalid > record but does not tell you that it has failed, or do you mean > something else? > > ColinSorry...it saves with the invalid (empty) values. Thanks, Brian -- 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-/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.
On 16 December 2010 16:14, Brian Penrose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #968879: >> On 16 December 2010 15:53, Brian Penrose <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> end >>> validates_presence_of :location >>> >>> Like I mentioned...the updates work fine, however when I try to edit >>> records and leave location empty, it still attempts to save the record >>> w/out first running validation. Any suggestions? >> >> What do you mean by ''attempts to save w/out first running >> validations''? Do you mean you get an exception, or do you mean it >> saves with invalid data, or do you mean it does not save the invalid >> record but does not tell you that it has failed, or do you mean >> something else? >> >> Colin > > Sorry...it saves with the invalid (empty) values. Thanks, BrianDo your unit tests pass ok, in particular the one that checks that a record cannot be saved with that field empty? Which version of Rails are you using? 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-/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.