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
Fauzia Masood
Courses Plus Student 1,793 PointsPaperclip Not Working! Error results!
It is giving me an error for the 'new' and 'create' in the Messages Controller! Please help as I have slaving over this for days to no avail... :( It says:
Paperclip::Error in MessagesController#create Document model missing required attr_accessor for 'attachment_file_name'
My Messages Controller!:
def new @message = Message.new @message.build_document respond_to do |format| format.html # new.html.erb format.json { render json: @message } end end
# GET /messages/1/edit def edit @message = Message.find(params[:id]) end
# POST /messages # POST /messages.json def create @message = Message.new(params[:message])
respond_to do |format|
if @message.save
format.html { redirect_to @message, notice: 'Message was successfully created.' }
format.json { render json: @message, status: :created, location: @message }
else
format.html { render action: "new" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
end
end
Here are my other models if that helps!
I have the Document Model:
attr_accessible :attachment, :attachment_file_name has_attached_file :attachment_file_name
I have the Messages (Status) Model:
attr_accessible :content, :user_id, :document_attributes belongs_to :user belongs_to :document accepts_nested_attributes_for :document validates_attachment_content_type :attachment, :content_type => [ 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ]
1 Answer
Jason Seifer
Treehouse Guest TeacherDo you have the has_attached_file declaration in your Message model?
Fauzia Masood
Courses Plus Student 1,793 PointsFauzia Masood
Courses Plus Student 1,793 PointsHey Jason I love your videos, they're awesome and you and Tim Hoskins are my personal heros!:
With that said. I added that and now it says:
Paperclip::Error in MessagesController#create Document model missing required attr_accessor for 'attachment_file_name'
I added 'attachment_file_name' to the doc model but its still giving me that error...
Jason Seifer
Treehouse Guest TeacherJason Seifer
Treehouse Guest TeacherDo you have attr_accessible :attachment in your Document model?
Fauzia Masood
Courses Plus Student 1,793 PointsFauzia Masood
Courses Plus Student 1,793 PointsYes I do.