Forum: Ruby on Rails Not able to save PDF Kit file to a Paperclip attachment in Rails 3.2.15

84bcd9fd8891e61a77898ae1c7af00f2?d=identicon&s=25 Ankur Kumar (Guest)
on 2014-01-30 21:07
(Received via mailing list)
I am trying to save a pdf file (generated using Rails PDFKit gem) to a
paperclip attachment. The MySQL table entry shows following for the
paperclip attachment after saving the generated PDF file:

*MySQL table record:*


id | resume_type | resume_attachment_file_name |
| resume_attachment_file_size | resume_attachment_updated_at

*1   | pdf   |   !ruby/object:File {}   |   NULL   |   NULL |   NULL |*


as against expected value to be something like in this format:

*resume.pdf | application/pdf | 38375 | 2014-01-30 18:24:34*


Can someone please tell me what's going wrong here?


html = render_to_string('resume.html.erb',layout: false)
kit =, :page_size => 'Letter')

file_name = "resume"

path = "#{Rails.root}/app/assets/PDF/" + file_name.to_s +
".pdf"**file** = kit.to_file(path)

document =>"pdf")
document.resume_attachment_file_name = **file**!


create_table "documents", :force => true do |t|
t.string   "resume_type"
t.string   "resume_attachment_file_name"
t.string   "resume_attachment_content_type"
t.integer  "resume_attachment_file_size"
t.datetime "resume_attachment_updated_at"



84bcd9fd8891e61a77898ae1c7af00f2?d=identicon&s=25 Ankur Kumar (Guest)
on 2014-01-31 04:07
(Received via mailing list)
The problem is solved. I forgot to add following in model:

has_attached_file :resume_attachment

In addition, I looked at
and saved the file in paperclip through File class

     my_model_instance =
     file =
     my_model_instance.attachment = file


Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.