Search code examples
paperclipruby-on-rails-3.2production-environment

paperclip not saving attachment in production


In my development environment I am able to create a download using paperclip successfully. In production the download will be created but the link to download does not work.

link that is created in development:

http://localhost:3000/downloads/files/3?1345315475

link that is created in production:

http://www.domain.com/attachments/original/missing.png

Here is the log from production when the download is created:

Started POST "/downloads" for xxx.xxx.xxx.xxx at 2012-08-18 11:47:31 -0700
Processing by DownloadsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"JhFMcjaui8cb4HCxTiIOjb/R2uxVJcOv3WEz8V0yoPp=", "download"=>{"school_id"=>"1", "software"=>"Follett", "original"=>"1", "makeup"=>"0", "visible"=>"1", "expired"=>"0"}, "commit"=>"Create Download"}
[paperclip] Saving attachments.
Rendered download_notice_mailer/download_notice.html.erb (1.9ms)

When I search for the download in the console (production)

irb(main):001:0> d = Download.last
Download Load (0.4ms)  SELECT `downloads`.* FROM `downloads` ORDER BY `downloads`.`id` DESC LIMIT 1
=> #<Download id: 8, visible: true, expired: false, software: "Skyward", created_at:    "2012-08-18 19:01:35", updated_at: "2012-08-18 19:01:35", school_name: "SCHOOL NAME", original: true, makeup: false, attachment_file_name: nil, attachment_content_type: nil, attachment_file_size: nil, attachment_updated_at: nil, school_id: 8, district_id: 2>

You will notice all attachment attributes are nil.

I am using rails 3.2.8 and paperclip 3.1.4

part of my download.rb model file

has_attached_file :attachment, :path => (Rails.root + "downloads/files/:id").to_s,
                             :url => "/downloads/files/:id"

validates_attachment_presence :attachment

attr_accessible :visible, :expired, :software, :school_name, :original, :makeup, :attachment, :school_id, :district_id

If any additional info is required please let me know.

Thanks,


Solution

  • Solved...

    Looks like I listed /downloads/files in my .gitignore file to prevent from test downloads being transfered to the server. I discovered the /downloads/files dir was missing on the server and paperclip was putting the files in /downloads (without error I might add). So after creating the files dir in downloads, everything is working as expected.