Paperclip ignores image sizing options - ruby-on-rails

So I've got the Paperclip gem setup in my project to handle cover images for a model called Story:
class Story < ActiveRecord::Base
...
has_attached_file :cover_image,
styles: { large: "700x700>", thumb: "300x300>" },
default_url: "#{Rails.root}/app/assets/images/default_image.jpg",
path:"/cover_images/:filename",
processors: [:thumbnail, :paperclip_optimizer]
I'm trying to use the thumb style for when the story is displayed in a small format, which looks like this:
<div class="image">
<%= image_tag story.cover_image.url(:thumb) %>
</div>
This is the way the Paperclip documentation says you should specify which style you want to use.
In this context, the image has the correct dimensions of 300x111px.
However, when I move to my story page, I want the large/full size version of the image:
<div class="header_image">
<%= image_tag(#story.cover_image.url(:large)) %>
Except paperclip incorrectly still uses the thumbnail version of the image:
Why isn't Paperclip sizing the images correctly?

You must specify a :style option in the path:
has_attached_file :cover_image,
styles: { large: "700x700>", thumb: "300x300>" },
default_url: "#{Rails.root}/app/assets/images/default_image.jpg",
path:"/cover_images/:filename/:style",
processors: [:thumbnail, :paperclip_optimizer]
Now Paperclip will upload different versions of the image and access them as needed:

Related

Paperclip image upload in rails

I am using paperclip for image uploading and in my model I have specified styles to store the images with various sizes, I have imagemagick installed, here are the codes
has_attached_file :image,
styles: { medium: '300x300>', thumb: '40x40>' },
path: 'images/:id/image/:basename.:extension',
default_url: 'default.png'
validates_attachment :image, content_type: { content_type: %w[image/jpeg image/png] }
It doesn't seems to store images with these specified styles, It only stores image with default style. Do I miss anything here?. Thanks in advance
I did a mistake by overriding the paperclip default path without :style specified. So it stores only the default size. The processed image (by ImageMagick) does not store as I didn't mention at override path.

paperclip: image not getting uploaded rails

I am using paperclip gem in rails,
my user model file contains:
has_attached_file :profile_pic, styles: { medium: "300x300>", thumb: "100x100>" },
default_url: "/images/:style/missing.png",
:url => "/assets/users/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/users/:id/:style/:basename.:extension"
My image is not getting uploaded and hence not getting displayed (broken Image with "missing.png" appears).what should i do to upload my image to /assets/images path ?
and My view part look like:
<%= image_tag current_user.profile_pic.url(:thumb) %>
It might be due to various reason
1) In strong parameter you need to define :profile_pic
2) you forgot to put missing.png
3):path =>:rails_root/public/assets/users/:id/:style/:basename.:extension"
it might be wrong way to define path first :class then :style and then after :extension
:path => "images/:class/:style/:id.:extension"

Rails paperclip resizing not working

I am trying to resize my images to 256x256 ignoring aspect ratio, so I used:
has_attached_file :thumbnail, styles: { medium: "256x256!", thumb: "300x300"}
in my model, and in view:
<%= image_tag guide.thumbnail(:medium), class: "guide_thumbnail" %>
but It fails to work. After changing to:
has_attached_file :thumbnail, styles: { medium: "50x50!", thumb: "300x300"}
Nothing changes, so I guess It is using default styles? How can I change it and force to use my ones instead? Please help.
PS: After adding newly named style:
has_attached_file :thumbnail, styles: { medium: "256x256!", thumb: "300x300", hihi: "50x50!"}
It does not show any image - only its name. I checked the logs and that is the error message:
ActionController::RoutingError (No route matches [GET] "/system/guides/thumbnails/000/000/088/hihi/test300.jpg"):
What should I do?
And Additionally I am curious if setting the width of an image via css(for example width: 256px;) is a good practice?
You can change into this:
has_attached_file :thumbnail, styles: { medium: "50x50>", thumb: "300x300"}
In my opinion, you'd better use image version properly with the real version.

Ruby on rails gem paperclip How to generate missing image

I uploaded a missing.png to public/images/ folder. But the the missing.png not showing correctly.
The website requires images/small/missing.png
So I guest I should generate the missing.png for thumb small medium large size.
What should I do?
Update 1:
I manually create a folder public/images/small and put missing.png inside the small folder. The website shows the missing.png. But What's is the correct way to generate all size of missing.png?
Try to add this in your model:
has_attached_file :image, styles: { :small => "150x150>", medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"

Paperclip change file system default storage RoR

I'm using paperclip to store and display images. I have change the default file system storage to:
has_attached_file :avatar,
:path => ":rails_root/upload/:rails_env/:class/:attachment/:id_partition/:style/:filename",
styles: { medium: "300x300>", thumb: "50x50>" }, default_url: "/images/:style/missing.png",
:url => "/upload/:rails_env/:class/:attachment/:id_partition/:style/:filename"
I want to store the images in the "upload" folder at the root of the application (Not in public). This part works fine.
The issue is the index and show view. I have:
<%= image_tag #user.avatar.url(:thumb) %>
Instead of showing the ":thumb" of the image I only get the file name. I don't know why!
I know the url is correct because it does get to the right image but only the name is display.
Any ideas?
Thanks in advance :)
Try <%= image_tag #user.avatar(:thumb) %>

Resources