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!

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

Brandon Barrette
Brandon Barrette
20,485 Points

Attaching files to Statuses

So I'm working though the third ruby on rails series and am having issues with attaching files using paperclip. The error only happens when I try to attach a file to the status, I am able to post a status without an attachment just fine. Here's the error

Paperclip::Error (Document model missing required attr_accessor for     'attachment_file_name'):
  app/controllers/statuses_controller.rb:46:in `create'

Here's my document model:

class Document < ActiveRecord::Base
  attr_accessible :attachment
  has_attached_file :attachment
end

Any my statuses controller is exactly the same, but here's the line it's asking for in question:

@status = current_user.statuses.new(params[:status])

Anyone else run into this issue or any recommendations on where to look Jason Seifer?

Thanks in advance!

1 Answer

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

That's pretty strange, @Brandon Barrette. Can you post a link to your code on GitHub?

Brandon Barrette
Brandon Barrette
20,485 Points

I'm a dummy. I made a typo the original time. When setting up the migration, I did this:

 add_attachment :documents, :add_attachment

and it was supposed to be this (note the extra :add_attachement for the column name)

 add_attachment :documents, :attachment

I changed it in the migration, ran rake db:setup, but didn't know about the schema.rb file. While attempting to build myself a simple forum today, I learned about this file and realized that was my error.

Thanks for all your help, I started playing around on my own today to design a simple forum and it went better than expected, thanks to your great teaching!

Excited to see the Push Updates tutorial series. Thanks again!