I followed the steps in the following link literally in a new Rails 2.2.2 project http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-one-through Then I ran it in script/console, getting these error (actually I got same error in another big rails project before I read that link): NoMethodError: undefined method `update_attributes'' for #<Class: 0xb7069980> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/base.rb:1833:in `method_missing'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_collection.rb:370:in `send'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_collection.rb:370:in `method_missing'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/base.rb:2003:in `with_scope'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_proxy.rb:202:in `send'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_proxy.rb:202:in `with_scope'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/association_collection.rb:366:in `method_missing'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations/has_one_through_association.rb:11:in `create_through_record'' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ active_record/associations.rb:1273:in `magazine='' from (irb):4 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I simply copied the code in that link, and in the associated table there were only needed fields to establish the relations. Regards, 林中鹏 On Sun, Jan 4, 2009 at 8:19 PM, Frederick Cheung <frederick.cheung@gmail.com> wrote:> > On 4 Jan 2009, at 08:29, Clive wrote: > > >> I followed the steps in the following link literally in a new Rails >> 2.2.2 project >> >> http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-one-through >> >> Then I ran it in script/console, getting these error (actually I got >> same error in another big rails project before I read that link): >> > > What's in the classes involved ? > > > Fre > >> >> >> NoMethodError: undefined method `update_attributes' for #<Class: >> 0xb7069980> >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/base.rb:1833:in `method_missing' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations/association_collection.rb:370:in `send' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations/association_collection.rb:370:in >> `method_missing' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/base.rb:2003:in `with_scope' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations/association_proxy.rb:202:in `send' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations/association_proxy.rb:202:in `with_scope' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations/association_collection.rb:366:in >> `method_missing' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations/has_one_through_association.rb:11:in >> `create_through_record' >> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/ >> active_record/associations.rb:1273:in `magazine=' >> from (irb):4 >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---
Andrius Chamentauskas
2009-Jan-05 15:03 UTC
Re: has_one :through doesn''t work in Rails 2.2.2
Maybe your defined rails version in environment.rb is not 2.2.2? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I was having the same issue as Clive trying to test the referenced example I was able to get some functionality by using :has_one subscription rather than :has_many. I do have a question though. I can set the through association like this user=User.create(:name=>"Bob") m=Magazine.create(:name=>''test'') user.magazine=m then user.subscription will = #<Subscription id: 1, user_id: 1, magazine_id: 1...> However, using user.update_attributes(:magazine=>m) the return is true, but there is no association created. Subscription remains nil. Am I wrong in assuming that I should be able to do this? On Jan 5, 10:03 am, Andrius Chamentauskas <sinsil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Maybe your defined rails version in environment.rb is not 2.2.2?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---