3
votes

I am pulling my hair out here... I have no idea why this isn't working.

I am using ruby 1.8.7, rails 3.0.19, paperclip 2.7.4.

My model:

has_attached_file :photo,  :styles => {
:logo => "60x20",
:widget => "60x40",
:thumb=> "100x100",
:small  => "150x150>" },
:url  => "/images/companies/:id/:style/:basename.:extension",
:path => ":rails_root/public/images/companies/:id/:style/:basename.:extension",
:default_url => "/images/bb_noimage.png"

#validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 3.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png','image/gif','image/jpg']

In views:

<%= image_tag "#{get_image_url(company.id,company.photo_file_name,"small")}"%>

The problem is some folders will have a "large" and "thumb" size but will not have a "small" and "logo" size - I am revisiting this site after a long time of having not used it. I want the missing styles to be generated. I tried these commands and the first shows no error, but the second shows the error below. Niether generate the needed thumbnails. Thank you for your help!

bundle exec rake paperclip:refresh:thumbnails CLASS=Company
bundle exec rake paperclip:refresh:missing_styles --trace

** Execute paperclip:refresh:thumbnails
rake aborted!
No such file or directory - /Users/q/Sites/baiabase-old/public/system/paperclip_attachments.yml
/Users/q/.rvm/gems/ruby-1.8.7-p302@baia-old/gems/paperclip-2.7.4/lib/paperclip/missing_attachment_styles.rb:25:in `initialize'
2
Does every image need a file named "original"?user963936

2 Answers

1
votes

add to your model

    attr_accessible :photo, :photo_file_name

    has_attached_file :photo,  :styles => {.....
....your code...

and in views

<%= image_tag @company.photo.url(:small) %>
-1
votes

And more to you as a gift, it is

For photos of the original 512x512 pixels will be better, will take up less space on your hard drive on the server

add style :original => "512x512", all attached photo converted maximum to this resolution, that save space on your hard drive.

:less_than => 3.megabytes change to :less_than => 5.megabytes If the user tries to attach a photo larger than 3 MB then it will not do it, change it to 5 MB

the user can add photos which has a resolution of 3000 x 3000 or more (<= 5 mb) but it was all smooth will be converted to 512 x 512 pixels which weight will be no more than 20 KB.

And if you want to convert all attached photos to jpg (format) try this :thumb => {:geometry => '100x100#', :format => :jpg},

and attentively with the Aspect ratio 4:3 '100x100#' and Aspect ratio 16:9 '100x100>'.