Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Dan S
Dan S
1,966 Points

Trouble with ActiveRecord associations rails

I have a Rails app that i'm using Paperclip with. I already have the app uploading a profile pic, which is great. I now want to be able to upload multiple attachments/files, per user. Therefore I have created an attachments table / model, and added the has_many to the user model, just like I did for a Comments model. This does not seem to work though.

Looking at Webrick, its not even selecting the records from the database. So I wondered if i'm missing something with the has_many association.

Dan S
Dan S
1,966 Points

This has been solved! It was because I incorrectly named the class all as one word, without separating with underscores (as normal). So to get round it without destroying the class and starting again, you can specify the class as follows:

has_many :user_file_attachment, :class_name => 'UserFileAttachments'