Hi ! i''ve different users subclasses organised thanks to STI under a user mother class, problem is that i can''t find a way to exchange a user form a certain type to an other , any light ??? class User < ActiveRecord::Base end class Guest < User has_and_belongs_to_many :hosts, :join_table => ''invitations'' end class Host < User has_and_belongs_to_many :guests, :join_table => ''invitations'' end #i''d like to change a Guest user to make him become Host :>> g = Guest.first=> #<Guest id: 418519017, type: "Guest", ...#> g.update_attributes!(:type=>''Host'') => true>> g=> #<Guest id: 418519017, type: "Guest", ...#> #It seems that this "type" attribute is protected is there a way to by-pass this ? you can find the pastie of the above code here : http://pastie.org/317885 -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-18 17:04 UTC
Re: STI updating the :type attribute of an STI instance
On Nov 18, 4:35 pm, nico Itkin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> => #<Guest id: 418519017, type: "Guest", ...#> > g.update_attributes!(:type=>''Host'') > => true>> g > > => #<Guest id: 418519017, type: "Guest", ...#> > > #It seems that this "type" attribute is protected is there a way to > by-pass this ?Yup (and if you check your logs you''d probably see a warning about not being able to mass assign a protected attribute) There''s two things you can play with: Directly setting the type attribute or playing with the becomes method. Fred> > you can find the pastie of the above code here :http://pastie.org/317885 > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Nov 18, 4:35�pm, nico Itkin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> => #<Guest id: 418519017, type: "Guest", ...#> >> g.update_attributes!(:type=>''Host'') >> => true>> g >> >> => #<Guest id: 418519017, type: "Guest", ...#> >> >> #It seems that this "type" attribute is protected is there a way to >> by-pass this ? > Yup (and if you check your logs you''d probably see a warning about not > being able to mass assign a protected attribute) > > There''s two things you can play with: Directly setting the type > attribute or playing with the becomes method. > > FredI had found update_attribute_with_validation_skipping which updates the protected attribute , but becomes is really what i need !! thanks a lot ! -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-18 17:27 UTC
Re: STI updating the :type attribute of an STI instance
On Nov 18, 5:25 pm, nico Itkin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote: > > I had found update_attribute_with_validation_skipping which updates the > protected attribute , but becomes is really what i need !! thanks a lot > !You don;t need to dig that deep even for updating the attribute - just foo.type = ''Blah'' would do it. Mass protection just means that it''s ignored if you do update_attributes, create, new or things like that. 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 Nov 18, 5:25�pm, nico Itkin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> Frederick Cheung wrote: >> >> I had found update_attribute_with_validation_skipping which updates the >> protected attribute , but becomes is really what i need !! thanks a lot >> ! > > You don;t need to dig that deep even for updating the attribute - just > foo.type = ''Blah'' would do it. > Mass protection just means that it''s ignored if you do > update_attributes, create, new or things like that. > > FredRealize that later, get mad cause update_attribute was not working thanks for the explanation nico -- 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 -~----------~----~----~----~------~----~------~--~---
Daniel Libanori
2008-Nov-19 19:15 UTC
Re: STI updating the :type attribute of an STI instance
I guess it is not the right thing to do. You should use something like roles and change it, not inheritance. On Nov 18, 4:09 pm, nico Itkin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote: > > On Nov 18, 5:25 pm, nico Itkin <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > >> Frederick Cheung wrote: > > >> I had found update_attribute_with_validation_skipping which updates the > >> protected attribute , but becomes is really what i need !! thanks a lot > >> ! > > > You don;t need to dig that deep even for updating the attribute - just > > foo.type = ''Blah'' would do it. > > Mass protection just means that it''s ignored if you do > > update_attributes, create, new or things like that. > > > Fred > > Realize that later, get mad cause update_attribute was not working > > thanks for the explanation > > nico > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---