0
votes

I have an app that works fine in on my development machine, but on my production server it uses a broken link to serve an image served using the Paperclip Gem.

Production environment is Linux(Debian), Apache, Passenger and I am deploying with Capistrano.

The app is stored in (a symlink that points to the public folder of the current version of the app deployed using capistrano):

/var/www/apps/root/appname

However, when I try and access it on the production server, the Apache error log displays this as the path it is looking in:

/var/www/apps/root/system

The correct path, however, is:

/var/www/apps/appname/shared/system

One option available to me is to create a symlink in root that directs system to the correct path, but I don't want to do this in case I want to deploy another app in the same root dir.

The url for this request is generated by rails, but Apache is what fetches the static resource (image files), so I have tried placing the following in my config/environments/production.rb:

ENV["RAILS_RELATIVE_URL_ROOT"] = '/appname/'

Which has resolved all other pathing issues I've been experiencing, but when rails generates the url (via the Paperclip gem), it doesn't seem to use it.

How can I set it so Paperclip uses the right path and only uses it production?

2
I have found this resource for setting the defaults of Paperclip but I am unable to understand the example or how to apply it to my situation.Dr.Seuss

2 Answers

1
votes

I've a workaround, add this as one of initializers:

config/initializer/paperclip.rb

Paperclip::Attachment.class_eval do 
  
  def url(style_name = default_style, options = {})
    if options == true || options == false # Backwards compatibility.
      res = @url_generator.for(style_name, default_options.merge(:timestamp => options))
    else
      res = @url_generator.for(style_name, default_options.merge(options))
    end
    # replace adding uri before res, minus final /
    Rails.application.config.site_relative_url[0..-2]+res
  end
  
end
0
votes

At the moment Paperclip doesn’t work with ENV['RAILS_RELATIVE_URL_ROOT'] and the. You can follow the issue here: https://github.com/thoughtbot/paperclip/issues/889