Hey there, I was following up on some tutorials about has_many(_and_belongs_to). There it was explain that i should make a join table as such: create_table ''cards_users'', :id => false do |t| t.column ''card_id'', :integer t.column ''user_id'', :integer end So i did, but now i wanna add a record via my rails console (@a Cards_users.create :card_id => 1, :user_id => 1) but it keeps telling me, whatever i try with the capitals etc., that Cards_users(and all other options) is an undefined method. What do i do?:( Thanks in advance -- 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.
Close. Try @a = CardUser.new Then @a.card_id = value & @a.user_id = value -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/t6Dns-JQr9oJ. 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.
Thanks alot, in that case i''d like to ask the following question (since after some tutorials it''s still unclear to me) I''ve got card_id = 1 and user_id = 1 in my DB now. In my user.rb i''ve got the has_and_belongs_to_many:cards and in cards i''ve got has_and_belongs_to_many:users. However, if i get all cards (@cards = Cards.all) and loop through them i don''t have a user_id in my loop. So what i''m actually trying to ask is, how do i get all cards that belong to user 1? -- 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 14 June 2012 13:23, Timen E. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks alot, > in that case i''d like to ask the following question (since after some > tutorials it''s still unclear to me) > > I''ve got card_id = 1 and user_id = 1 in my DB now. In my user.rb i''ve > got the has_and_belongs_to_many:cards and in cards i''ve got > has_and_belongs_to_many:users. However, if i get all cards (@cards > Cards.all) and loop through them i don''t have a user_id in my loop. > > So what i''m actually trying to ask is, how do i get all cards that > belong to user 1?If you have a User in @user then all his cards are available as @user.cards I think it would be worth your while working through good tutorial such as railstutorial.org which is free to use online. Then you will learn the fundamentals of Rails. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.