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

Karina Mio
3,863 PointsIssues Attaching Files to Statuses
I've been following the Advanced Social Features in Ruby on Rails series and I'm currently stuck on the Displaying Files video. Every time I try to post a new status with a file attachment, I get this error:
Paperclip::Error in StatusesController#create Document model missing required attr_accessor for 'attachment_file_name'
I've already searched the Treehouse Forums thoroughly for all related posts. After implementing the suggested solutions, I end up with this error instead:
undefined method `attachment_content_type' for #<Document:0x007fdb9b049858>
app/controllers/statuses_controller.rb:43:in `create'
Now I'm stuck and I'm not sure what went wrong. Any help would be greatly appreciated, thanks!
Here's my document model:
class Document < ActiveRecord::Base
attr_accessible :attachment
has_attached_file :attachment
attr_accessor :attachment_file_name
validates_attachment_content_type :attachment, :content_type => %w(image/jpeg image/jpg image/png image/gif)
end
5 Answers

Brandon Barrette
20,485 PointsWhat's in your statuses_controller, this error here:
app/controllers/statuses_controller.rb:43:in `create'
In fact, please paste your entire create method under statuses_controller.

Karina Mio
3,863 Pointsdef create
@status = current_user.statuses.new(params[:status])
respond_to do |format|
if @status.save
format.html { redirect_to @status, notice: 'Status was successfully created.' }
format.json { render json: @status, status: :created, location: @status }
else
format.html { render action: "new" }
format.json { render json: @status.errors, status: :unprocessable_entity }
end
end
end
I changed my document model to this, and I no longer get an error. However, the file still doesn't attach to the status...
class Document < ActiveRecord::Base
attr_accessible :attachment
has_attached_file :attachment
do_not_validate_attachment_file_type :attachment
attr_accessor :attachment_file_name
end
Thanks!

Karina Mio
3,863 PointsSee above.

Jason Seifer
Treehouse Guest TeacherKarina Mio What does your log say when you attach an attachment? Can you possibly post a link to your code so we can take a look?

Karina Mio
3,863 PointsNevermind, I got it.