Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

error for attaching files to statuses

Hey guys,

i havnt really had any trouble until now, but I could use some help. I'm in the advanced RoR tutorials, trying to add files to the status updates. I've gone through the videos twice and still havnt caught my error.

when I try to attach a file I'm given this error...

Paperclip::Error in StatusesController#create Document model missing required attr_accessor for 'attachment_file_name'

my create documents migration looks like this...

class CreateDocuments < ActiveRecord::Migration
 def change
   create_table :documents do |t|
      t.integer :user_id
      t.timestamps
 end

  add_index :documents, :user_id
  add_attachment :documents, :attachment
  add_column :statuses, :document_id, :integer

  end
end

for documents.rb I have this

class Document < ActiveRecord::Base

  attr_accessible :attachment
  has_attached_file :attachment
end

and added the @status.build_document to my new method in status controller

this is the repository for any other information https://github.com/mitchcail/Chipper

Jason Seifer, have you come across this problem at all? or know how to fix it?

thanks, mitch

1 Answer

Hey Mitch,

I had the same problem and it's the exact error Brandon Barrette mentions in his post https://teamtreehouse.com/forum/attaching-files-to-statuses.

However, unlike Brandon's post, your problem and my problem don't seem to be related to a mistype. It's possible I missed something, but we seem to have the same code.

I was able to fix the problem by adding the line

  attr_accessor :attachment_file_name

into my document model. Now, I feel like this is redundant since my document model already has

attr_accessible :attachment

which, to me, the attachment file name would be an attribute of the attachment, rendering the code I added unnecessary.

In any case, I know it works, but may be "improper." If anyone has anything to add I'd love to hear it.

Hope that helps, Mitch!

-Evan-