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

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-