While using the in place editor, I noticed that none of my validations were firing. Digging around in the docs I found that this is deliberate. http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909 This method is overwritten by the Validation module that''ll make sure that> updates made with this method doesn''t get subjected to validation checks. > Hence, attributes can be updated even if the full object isn''t valid.In the validations module, alias_method_chain :update_attribute, :validation_skipping # Updates a single attribute and saves the record without going through the normal validation procedure. # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method # in Base is replaced with this when the validations module is mixed in, which it is by default. def update_attribute_with_validation_skipping(name, value) send(name.to_s + ''='', value) save(false) end Why would validations be turned off by default when using in place editors? and also why would update_attribute have validation turned off by default with no apparent way of turning it back on? Can anyone explain this to me please. Cheers --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry to cross post from Rails ML but I did not get any response, and this is really bugging me... ---------- Forwarded message ---------- From: Daniel N <has.sox@gmail.com> Date: Sep 30, 2006 11:08 PM Subject: update_attribute does not validate? To: rubyonrails-talk@googlegroups.com While using the in place editor, I noticed that none of my validations were firing. Digging around in the docs I found that this is deliberate. http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909 This method is overwritten by the Validation module that''ll make sure that> updates made with this method doesn''t get subjected to validation checks. > Hence, attributes can be updated even if the full object isn''t valid.In the validations module, alias_method_chain :update_attribute, :validation_skipping # Updates a single attribute and saves the record without going through the normal validation procedure. # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method # in Base is replaced with this when the validations module is mixed in, which it is by default. def update_attribute_with_validation_skipping(name, value) send(name.to_s + ''='', value) save(false) end Why would validations be turned off by default when using in place editors? and also why would update_attribute have validation turned off by default with no apparent way of turning it back on? Can anyone explain this to me please. Cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
I would guess it''s that way because inplace editing should accept anything you give it and deal with the input as is. How would you report back a failed validation? An alert? I''m guessing you probably don''t want inplace editing for the text you''re trying to modify and if you do, you should update your logic to convert any bad data into something that will work for you. An example being an inplace edit where you input html when it''s not allowed, and you simply remove the "invalid" html on the server side to make it valid. Anyway, that''s my guess. On 10/2/06, Daniel N <has.sox@gmail.com> wrote:> Sorry to cross post from Rails ML but I did not get any response, and this > is really bugging me... > > ---------- Forwarded message ---------- > From: Daniel N < has.sox@gmail.com> > Date: Sep 30, 2006 11:08 PM > Subject: update_attribute does not validate? > To: rubyonrails-talk@googlegroups.com > > While using the in place editor, I noticed that none of my validations were > firing. Digging around in the docs I found that this is deliberate. > > http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909 > > > This method is overwritten by the Validation module that''ll make sure that > updates made with this method doesn''t get subjected to validation checks. > Hence, attributes can be updated even if the full object isn''t valid. > > In the validations module, > > alias_method_chain :update_attribute, :validation_skipping > # Updates a single attribute and saves the record without going through the > normal validation procedure. > # This is especially useful for boolean flags on existing records. The > regular +update_attribute+ method > > > # in Base is replaced with this when the validations module is mixed in, > which it is by default. > def update_attribute_with_validation_skipping(name, value) > send(name.to_s + ''='', value) > save(false) > > > end > Why would validations be turned off by default when using in place editors? > and also why would update_attribute have validation turned off by default > with no apparent way of turning it back on? > > Can anyone explain this to me please. > > Cheers > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
On 10/2/06, Andrew Kaspick <akaspick@gmail.com> wrote:> > > I would guess it''s that way because inplace editing should accept > anything you give it and deal with the input as is. How would you > report back a failed validation? An alert? > > I''m guessing you probably don''t want inplace editing for the text > you''re trying to modify and if you do, you should update your logic to > convert any bad data into something that will work for you. An > example being an inplace edit where you input html when it''s not > allowed, and you simply remove the "invalid" html on the server side > to make it valid. > > Anyway, that''s my guess.Thanx for the feedback. In general though you don''t write much when using an in_place**. You use an in_place_edit_for in the controller to setup the methods, and use in_place_editor_field in the view. I think more importantly than reporting back that a validation failed, ( at the moment until I work out something) is the fact that there is no validation performed in the first place. I could manually declare the methods in the controller but I don''t want to have to declare validation logic in my in_place editor methods (view/controller centric). My model should look after it''s own data. I guess I could also overwrite update_attribute to use validataion, but why was validation removed from this method in the first place? I don''t want to go breaking things... Cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
> I guess I could also overwrite update_attribute to use validataion, but why > was validation removed from this method in the first place? I don''t want to > go breaking things...Most of the other core guys are in bed right now, but I''ve never used the in place editor, and I share your surprise that it deliberately avoids validation. Perhaps David, Tobi, Thomas or Rick could chime in? On the other hand, it''s been deprecated in trunk, so perhaps this is a good opportunity for someone to extract it to a plugin and make it much more robust and feature filled? -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
On 10/2/06, Michael Koziarski <michael@koziarski.com> wrote:> > > > I guess I could also overwrite update_attribute to use validataion, but > why > > was validation removed from this method in the first place? I don''t > want to > > go breaking things... > > Most of the other core guys are in bed right now, but I''ve never used > the in place editor, and I share your surprise that it deliberately > avoids validation. Perhaps David, Tobi, Thomas or Rick could chime > in? On the other hand, it''s been deprecated in trunk, so perhaps > this is a good opportunity for someone to extract it to a plugin and > make it much more robust and feature filled?Thanx for the feedback... I didn''t realise it was depricated. That still leaves the issue of update_attribute though. I guess I''ll wait for other guys. Thanx again for the feedback. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
It will be a plugin eventually, so you can still use it as is, but you''ll have to install a plugin when a later rails version is released. The case you''re speaking of is partially one reason why it will be a plugin; too many people want it to do different things and when that happens the functionality should remain as a plugin for a while (if not forever). On 10/2/06, Daniel N <has.sox@gmail.com> wrote:> > > On 10/2/06, Michael Koziarski <michael@koziarski.com> wrote: > > > > > I guess I could also overwrite update_attribute to use validataion, but > why > > > was validation removed from this method in the first place? I don''t > want to > > > go breaking things... > > > > Most of the other core guys are in bed right now, but I''ve never used > > the in place editor, and I share your surprise that it deliberately > > avoids validation. Perhaps David, Tobi, Thomas or Rick could chime > > in? On the other hand, it''s been deprecated in trunk, so perhaps > > this is a good opportunity for someone to extract it to a plugin and > > make it much more robust and feature filled? > > Thanx for the feedback... I didn''t realise it was depricated. That still > leaves the issue of update_attribute though. I guess I''ll wait for other > guys. Thanx again for the feedback. > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core -~----------~----~----~----~------~----~------~--~---
Does anyone have any thoughts as to why the update_attribute method does not validate, and has no way to turn validation on? Cheers On 9/30/06, Daniel N <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > While using the in place editor, I noticed that none of my validations > were firing. Digging around in the docs I found that this is deliberate. > > http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909 > > This method is overwritten by the Validation module that''ll make sure that > > updates made with this method doesn''t get subjected to validation checks. > > Hence, attributes can be updated even if the full object isn''t valid. > > > In the validations module, > > alias_method_chain :update_attribute, :validation_skipping > > # Updates a single attribute and saves the record without going through the normal validation procedure. > # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method > > # in Base is replaced with this when the validations module is mixed in, which it is by default. > def update_attribute_with_validation_skipping(name, value) > send(name.to_s + ''='', value) > save(false) > > end > > Why would validations be turned off by default when using in place > editors? and also why would update_attribute have validation turned off by > default with no apparent way of turning it back on? > > Can anyone explain this to me please. > > Cheers > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think having this method NOT validate is useful for the handful of situations in which you want to update the underlying database even though the valid object hasn''t been fully saved. Eg, model = Model.find(42) # do something invalid model.update_attribute(:invalid, true) unless model.save I''ve never run into a situation where I''ve needed this, but it''s nice to know it''s there. You may want to use Ruby''s class rewriting capabilities to update the in_place_edit_for method to use #update_attributes (which will do validation checks): module ActionController module Macros module InPlaceEditing module ClassMethods def in_place_edit_for(object, attribute, options = {}) define_method("set_#{object}_#{attribute}") do @item = object.to_s.camelize.constantize.find(params[:id]) @item.update_attributes({ attribute => params[:value] }) render :text => @item.send(attribute) end end end end end end Or, you can just write out your own set_* methods. Daniel N wrote:> While using the in place editor, I noticed that none of my validations were > firing. Digging around in the docs I found that this is deliberate. > > http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909 > > This method is overwritten by the Validation module that''ll make sure that > > updates made with this method doesn''t get subjected to validation checks. > > Hence, attributes can be updated even if the full object isn''t valid. > > > In the validations module, > > alias_method_chain :update_attribute, :validation_skipping > > # Updates a single attribute and saves the record without going > through the normal validation procedure. > # This is especially useful for boolean flags on existing records. > The regular +update_attribute+ method > # in Base is replaced with this when the validations module is > mixed in, which it is by default. > def update_attribute_with_validation_skipping(name, value) > send(name.to_s + ''='', value) > save(false) > end > > Why would validations be turned off by default when using in place editors? > and also why would update_attribute have validation turned off by default > with no apparent way of turning it back on? > > Can anyone explain this to me please. > > Cheers > > ------=_Part_20109_7921093.1159621739816 > Content-Type: text/html; charset=ISO-8859-1 > X-Google-AttachSize: 1578 > > While using the in place editor, I noticed that none of my validations were firing. Digging around in the docs I found that this is deliberate. <br><br><a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909"> > http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000909</a><br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><span style="font-style: italic;"> > This method is overwritten by > the Validation module that''ll make sure that updates made with this > method doesn''t get subjected to validation checks. Hence, attributes > can be updated even if the full object isn''t valid.</span></blockquote><div><br>In the validations module,<br><br> > <pre>alias_method_chain :update_attribute, :validation_skipping</pre> > <pre># Updates a single attribute and saves the record without going through the normal validation procedure.<br> # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method > <br> # in Base is replaced with this when the validations module is mixed in, which it is by default.<br> def update_attribute_with_validation_skipping(name, value)<br> send(name.to_s + ''='', value)<br> save(false) > <br> end</pre> Why would validations be turned off by default when using in place editors? and also why would update_attribute have validation turned off by default with no apparent way of turning it back on?<br><br>Can anyone explain this to me please. > <br><br>Cheers<br></div><br> > > ------=_Part_20109_7921093.1159621739816----~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---