Hello all,
I’m quite baffled/agitated by this. I’m using paperclip to allow upload
of images to my application. This is working fine, it’s saving the the
images exactly where its supposed to and it’s saving the image objects
as its supposed to.
The problem is that I can’t display these images in the browser. I’ve
had this issue in a couple other applications I’ve made and just got
around it by having paperclip save to the public folder and pull from
there to display the desired image. But I feel as though I should get
this sorted out.
So here goes:
My image model (paperclip)
class Image < ActiveRecord::Base
class ContentType
IMAGES = [“image/png”, “image/x-png”, “image/jpg”, “image/jpeg”,
“image/pjpeg”, “image/gif”, “image/bmp”, “image/tiff”]
GIF = [“image/gif”]
def self.allowed_types
IMAGES + GIF
end
end
belongs_to :attachable, :polymorphic => true
has_attached_file :attachment,
:path =>
“:rails_root/uploaded/:attachable_type/:attachable_id/:id_:style.:extension”,
:url => “/images/:id_:style.:extension”,
:styles => lambda { |attachment|
ContentType::IMAGES.include?(attachment.instance_read(:content_type)) ?
{ :thumb => [“80x80>”,
:png], :preview => [“400x400>”, :png], :large => [“1000x1000>”, :png] }
:
ContentType::GIF.include?(attachment.instance_read(:content_type))
?
{:thumb =>
[“80x80>”, :png], :preview => [“400x400>”, :gif], :large =>
[“1000x1000>”, :gif] } :
{} },
:default_style => :preview
validates_attachment_size :attachment, :in =>
1.kilobytes…24.megabytes
validates_attachment_content_type :attachment, :content_type =>
ContentType.allowed_types
… code omitted
end
I have included this line in my ‘config/environments/development.rb’
file
config.action_dispatch.x_sendfile_header = “X-Sendfile”
and I have the mod_xsendfile.x.x.so in my vhost:
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot “/Users//Sites/myapp/public”
RackEnv development
XSendFile on
#XSendFileAllowAbove on
XSendFilePath /Users//Sites/myapp
<Directory “/Users//Sites/myapp/public”>
Order allow,deny
Allow from all
When I print out the image.url and the image.path I get:
/images/2_preview.png?1315164150
/Users//Sites/myapp/uploaded/avatars/1/2_preview.png
Any help here would be greatly appreciated. I’m at a loss as to how
this is not working.