Paperclip

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.

Good morning Alfredo :wink:

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

Den 05/04/2014 kl. 08.55 skrev Alfredo B. [email protected]:

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! :slight_smile:
Use CSS only for minimal changes of size.

Bye

2014-04-05 8:55 GMT+02:00 Alfredo B. [email protected]:

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 B. escribió:

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

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

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.

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

Any idea of the issues?.

Thanks a lot.

Alfredo.

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 :frowning:

Regards.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs