Joshua Muheim
2009-Oct-13 17:25 UTC
attr_accessible :field - obj.field="xxx" still possible?!
Hi all MyClass < ActiveRecord::Base attr_protected :field end In script/console: x = MyClass.find 1 # => field = "original" x.field="blah" # => "blah" x.save # => ... x = MyClass.find 1 # => field = "original" Why is there still a field=() method (even though it doesn''t work when saving the object), when I have set it to protected? Thanks Josh -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Oct-13 17:29 UTC
Re: attr_accessible :field - obj.field="xxx" still possible?!
On Oct 13, 6:25 pm, Joshua Muheim <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all > > MyClass < ActiveRecord::Base > attr_protected :field > end > > In script/console: > > x = MyClass.find 1 > # => field = "original" > x.field="blah" > # => "blah" > x.save > # => ... > x = MyClass.find 1 > # => field = "original" > > Why is there still a field=() method (even though it doesn''t work when > saving the object), when I have set it to protected? >because that''s not what attr_protected is supposed to do - it is only supposed to stop the field getting updated when you do object.update_attributes(...) and similar. why the save isn''t working for you is another issue. Fred> Thanks > Josh > -- > Posted viahttp://www.ruby-forum.com/.
Joshua Muheim
2009-Oct-13 17:35 UTC
Re: attr_accessible :field - obj.field="xxx" still possible?!
> because that''s not what attr_protected is supposed to do - it is only > supposed to stop the field getting updated when you do > object.update_attributes(...) and similar. why the save isn''t working > for you is another issue.OK, so it is normal, that every field in the database has its own getter and, method whether it is protected or not, right? Thanks. -- Posted via http://www.ruby-forum.com/.
Joshua Muheim
2009-Oct-13 19:03 UTC
Re: attr_accessible :field - obj.field="xxx" still possible?!
Joshua Muheim wrote:>> because that''s not what attr_protected is supposed to do - it is only >> supposed to stop the field getting updated when you do >> object.update_attributes(...) and similar. why the save isn''t working >> for you is another issue. > > OK, so it is normal, that every field in the database has its own getter > and, method whether it is protected or not, right? Thanks.Now I just redeclared the field=(str) method to be private. Would you suggest this to be a clean way to "unset" the method? -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser
2009-Oct-13 20:51 UTC
Re: attr_accessible :field - obj.field="xxx" still possible?
Joshua Muheim wrote: [...]> Now I just redeclared the field=(str) method to be private. Would you > suggest this to be a clean way to "unset" the method?No. If you want to do that, use remove_method or undef_method. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.