Paperclip

59 views
Skip to first unread message

Alfredo Barrero

unread,
Apr 5, 2014, 2:55:59 AM4/5/14
to rubyonra...@googlegroups.com
Good afternoon everyone.


Im using the gem Paperclip in order to upload the images of the users to my server. But I having problems with it. I don't know how to resize the image size after uploading the image.

I'm using CSS to try to change the size but is not working. I think Paperclip is showing the exactly size that it was saved. Could anyone help me?.


Another question is about the location of the pictures that the gem Paperclip is using. When I add a picture with this gem, Where it is saved?.


Thank you & best regards.

Alfredo.

Walther Diechmann

unread,
Apr 5, 2014, 3:35:50 AM4/5/14
to rubyonra...@googlegroups.com
Good morning Alfredo ;)

file sizes:

Paperclip will post process (resize) your images - if all validations are ok - otherwise post processing will not commence. 

Paperclip supports an extensible selection of post-processors. When you define a set of styles for an attachment, by default it is expected that those "styles" are actually "thumbnails". However, you can do much more than just thumbnail images. By defining a subclass of Paperclip::Processor, you can perform any processing you want on the files that are attached.

eg.: has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }

this image will have two resized copies, a medium and a thumb
which you may show using a helper:

<%= image_tag @user.avatar.url(:medium) %>


location of file:

(from https://github.com/thoughtbot/paperclip - understanding storage): The files that are assigned as attachments are, by default, placed in the directory specified by the :path option to has_attached_file. By default, this location is :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename


cheers,
Walther

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d057d5d7-a3cf-42da-a648-a7c154ed5b24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tommaso Visconti

unread,
Apr 5, 2014, 3:37:24 AM4/5/14
to rubyonra...@googlegroups.com
Hi Alfredo,
both your questions are answered in the README of the github project: https://github.com/thoughtbot/paperclip

The sizes can be choosed with the :styles param of the `has_attached_file` method (in the model):


has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }

In your view you can select the style to show:


<%= image_tag @user.avatar.url(:medium) %>

The files are saved in public/system. Read the "Storage" paragraph of the README for a better comprehension

NOTE:
Remember, when using CSS to show different sizes of an image, that the image is downloaded in the original size: if you show an image 200x200 px (using css) but the image is 2000x2000 (1 or 2 MB) you download the full image, which is a very slow solution! :)
Use CSS only for minimal changes of size.

Bye



--

Alfredo Barrero

unread,
Apr 5, 2014, 3:45:16 AM4/5/14
to rubyonra...@googlegroups.com
Thank both of you for the answer. I'm going to try it now. I'll update this with the results.

Thank you & Best regards.

Alfredo.

Alfredo Barrero

unread,
Apr 5, 2014, 7:46:08 AM4/5/14
to rubyonra...@googlegroups.com
Hi there,

I've been problems using this line:  "<%= image_tag @user.avatar.url(:medium) %>"

When I use that line, in the browser I just can see text instead of the picture. And RubyMine does not recognize "avatar". If I use this line the browser shows the picture but I cant resize the picture.  <%= image_tag @user.avatar_file_name %>

Any idea?.

Thank you.

Alfredo.

El sábado, 5 de abril de 2014 14:55:59 UTC+8, Alfredo Barrero escribió:

Walter Lee Davis

unread,
Apr 5, 2014, 9:24:08 AM4/5/14
to rubyonra...@googlegroups.com

On Apr 5, 2014, at 7:46 AM, Alfredo Barrero wrote:

> Hi there,
>
> I've been problems using this line: "<%= image_tag @user.avatar.url(:medium) %>"
>
> When I use that line, in the browser I just can see text instead of the picture. And RubyMine does not recognize "avatar". If I use this line the browser shows the picture but I cant resize the picture. <%= image_tag @user.avatar_file_name %>
>
> Any idea?.
>
> Thank you.
>
> Alfredo.

Is your attachment called avatar? Or is it called something else, like picture? In the example code, they are presuming that your attachment is called avatar, and everything proceeds from that point.

Walter

>
> El sábado, 5 de abril de 2014 14:55:59 UTC+8, Alfredo Barrero escribió:
> Good afternoon everyone.
>
>
> Im using the gem Paperclip in order to upload the images of the users to my server. But I having problems with it. I don't know how to resize the image size after uploading the image.
>
> I'm using CSS to try to change the size but is not working. I think Paperclip is showing the exactly size that it was saved. Could anyone help me?.
>
>
> Another question is about the location of the pictures that the gem Paperclip is using. When I add a picture with this gem, Where it is saved?.
>
>
> Thank you & best regards.
>
> Alfredo.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0edcf87c-16f7-46a7-9fb1-bd43968db3b9%40googlegroups.com.

Alfredo Barrero

unread,
Apr 8, 2014, 12:31:41 AM4/8/14
to rubyonra...@googlegroups.com
I'm not 100% sure but I think is called "avatar". Below is the table of users that is in the database.


     id = 1
               name = alf
    password_digest = $2a$10$CKi0spNsaEpozAJ9voAHJ.hH76Ca0hdmGCePVVvvXHHS9qQ8CDARC
              photo = alf
         created_at = 2014-04-07 12:54:07.328582
         updated_at = 2014-04-07 12:54:07.328582
   avatar_file_name = alf.jpg
avatar_content_type = image/jpeg
   avatar_file_size = 12425
  avatar_updated_at = 2014-04-07 12:54:07.173774

Could you check if is good configured?.


I'm also having a new error. When I try to print all the pictures that the user has with the following line, Ruby does not recognize the data.

users/show.html.erb => <% @photos.each do |product| %>
users_controller.rb => @photos = Photo.order(:title)

Could you please check why I can't acces to the data of Photos?. The browser give me this error =>
undefined method `each' for nil:NilClass

Thank you and sorry for the long text :(

Regards.

El sábado, 5 de abril de 2014 14:55:59 UTC+8, Alfredo Barrero escribió:

Alfredo Barrero

unread,
Apr 10, 2014, 12:40:13 AM4/10/14
to rubyonra...@googlegroups.com
Any idea of the issues?.

Thanks a lot.

Alfredo.
Reply all
Reply to author
Forward
0 new messages