join table naming

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]) …       if << @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 - is it an attribute of @question because of the join table?


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.

I will give the same answer that I usually do for beginners, which is to work right through a good tutorial such as 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.


In addition, thorough reading and re-reading of Active Record Associations — Ruby on Rails Guides is essential.