Hi, I’m an amateur learning rails and could use some help… I created a join table “pictures_questions” and append to it in the following way: @picture = Picture.new(params[:picture]) … if @picture.save @question.pictures << @picture Everything works fine but honestly I think I got this working by sheer luck and trial and error. I have 2 questions: 1. I do not understand the difference between naming the join table pictures_questions vs questions_pictures (ie how to decide which to use) 2. I do not understand the “.pictures” in @question.pictures - is it an attribute of @question because of the join table? Thanks -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
1 - You name it "pictures_questions" because they are in alphabetical order that way, and that''s what Rails assumes 2 - Yes, it is an attribute of Question because you specified "has_and_belongs_to_many :pictures" in your model. Then rails assumes there will be a join table. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/5V-1dPcMqEQJ. For more options, visit https://groups.google.com/groups/opt_out.
On 24 April 2013 19:00, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > I’m an amateur learning rails and could use some help… > I created a join table “pictures_questions” > and append to it in the following way: > @picture = Picture.new(params[:picture]) > … > if @picture.save > @question.pictures << @picture > > Everything works fine but honestly I think I got this working by sheer > luck and trial and error. I have 2 questions: > 1. I do not understand the difference between naming the join table > pictures_questions vs questions_pictures (ie how to decide which to use) > 2. I do not understand the “.pictures” in @question.pictures - is it > an attribute of @question because of the join table?I will give the same answer that I usually do for beginners, which is to work right through a good tutorial such as railstutorial.org in order to understand the basics of Rails, then you should be able to answer the questions, and many of the ones that come hereafter, yourself. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Wed, Apr 24, 2013 at 2:47 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 24 April 2013 19:00, Dave Castellano <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi, >> I’m an amateur learning rails and could use some help… >> I created a join table “pictures_questions” >> and append to it in the following way: >> @picture = Picture.new(params[:picture]) >> … >> if @picture.save >> @question.pictures << @picture >> >> Everything works fine but honestly I think I got this working by sheer >> luck and trial and error. I have 2 questions: >> 1. I do not understand the difference between naming the join table >> pictures_questions vs questions_pictures (ie how to decide which to use) >> 2. I do not understand the “.pictures” in @question.pictures - is it >> an attribute of @question because of the join table? > > I will give the same answer that I usually do for beginners, which is > to work right through a good tutorial such as railstutorial.org in > order to understand the basics of Rails, then you should be able to > answer the questions, and many of the ones that come hereafter, > yourself. > > ColinIn addition, thorough reading and re-reading of http://guides.rubyonrails.org/association_basics.html is essential. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.