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/<username>/Sites/myapp/public"
RackEnv development
XSendFile on
#XSendFileAllowAbove on
XSendFilePath /Users/<username>/Sites/myapp
<Directory "/Users/<username>/Sites/myapp/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
----------------------------------------
When I print out the image.url and the image.path I get:
/images/2_preview.png?1315164150
/Users/<username>/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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 11, 1:29 am, Keith Raymond <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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",> > When I print out the image.url and the image.path I get: > /images/2_preview.png?1315164150 > /Users/<username>/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.Unless you''ve got an ImagesController (not shown here), the :url argument you''re using is the problem. Files in the public directory are served as-is, so yours will be in / uploaded/:attachable_type/:attachable_id/:id_:style.:extension --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok that makes sense. Thank you.
Though I''m still not getting this to work. Where do I go from here?
I created the images_controller and created routes for them. I looked
into this and saw some one else doing this in their controller to handle
''documents'' (pdfs, jpgs, pngs, etc)
----------------------------------------
def show
@image = Image.find(params[:id])
respond_to do |format|
@imgstyle = params[:style].blank? ? # ERROR B?C imgstyle == nil
params[:format].blank? ? nil : params[:format].to_sym :
params[:style]
mime_type = case @imgstyle
when :thumb, :preview then "jpeg"
when :original then "tiff"
end
# render show action
format.html {}
# send original for download
format.original { |format| send_file @image.path(:original),
:filename => @image.filename }
# used with image_tag helper to send file to the browser
format.any { |format| send_file @image.path(@imgstyle), :type
=> "image/#{mime_type}", :filename => @image.filename,
:disposition =>
''inline'' }
end
end
------------------------------
and it makes sense, but how do I get my show action for Character
(characters/show.html.haml) to contact the images_controller for the
show action?
Again thank you for your help. Definitely pointed my in the right
direction.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Anyone have anything they can add? Any help at this point would be appreciated. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Does anyone have any ideas on this? Please I''m still desperate for an answer -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
why don''t you use the standard and simple way ?
this is what I have in my app :
model Product
has_attached_file :product_image, :styles => { :left =>
''225>x238>'', :big => ''600x600>''}
# product_image_file_name :string(255)
# product_image_content_type :string(255)
# product_image_file_size :integer(4)
# product_image_updated_at :date time
uploads are saved in /public/system/product_images/:id/big/* /public/
system/product_images/:id/left/* /public/system/product_images/:id/
original/*
I display the pictures with the following url ::
@product.product_image.url(:left) @product.product_image.url(:big)
@product.product_image.url
On 14 oct, 03:36, Keith Raymond
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Does anyone have any ideas on this?
>
> Please I''m still desperate for an answer
>
> --
> Posted viahttp://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Try adding "public" to your path: :path => ":rails_root/public/ uploaded/:attachable_type/:attachable_id/:id_:style.:extension " Then you can just link directly to it: <img src="/uploaded/:attachable_type/:id/:id_:style.:extension" /> On Oct 13, 6:36 pm, Keith Raymond <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Does anyone have any ideas on this? > > Please I''m still desperate for an answer > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
For those of you who recommend the public folder, the only problem with that for me and I''m sure others is that we may want some uploads to be private, and prevent users from simply browsing the public directory on our webapps to look at every-bodies uploads. By using our own custom folders we can prevent this with very little code. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Monday, 7 May 2012 14:01:50 UTC-4, Ruby-Forum.com User wrote:> > For those of you who recommend the public folder, the only problem with > that for me and I''m sure others is that we may want some uploads to be > private, and prevent users from simply browsing the public directory on > our webapps to look at every-bodies uploads. By using our own custom > folders we can prevent this with very little code. > >By correctly configuring your server, you can prevent this without *any* code. "Options -Indexes" on Apache, "autoindex off" in nginx. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/M7JuN6H-7I0J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.