kwyoung11
kwyoung11

Reputation: 978

default_style not working in Paperclip on Rails 3.2.1

I'm trying to use default_style in my application which is running on Paperclip 2.2.5 on Rails 3.2.1. For some reason, it is still defaulting to the original size even when I specify to use a smaller size. Here is the model in which I have defined the attached file:

class Profile < ActiveRecord::Base
has_one :user

has_attached_file :cover_image,
                :styles => { :thumb => "x70", :super_thumb => "x28" },
                :default_style => :thumb,
                :url => "/assets/products/:id/:style/:basename.:extension",  
                :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension",
                :default_url =>  "/assets/products/default/default_:style_pic.jpg"

end

When a user creates his/her profile without uploading an image, the default picture with the original size gets put there. The problem is I want it to be the :thumb size, as specified above. Anyone know why this isn't working?

Thanks.

Upvotes: 1

Views: 1390

Answers (1)

kwyoung11
kwyoung11

Reputation: 978

Nevermind, I figured this out. For those that may have the same problem, add a file called paperclip.rb to config/initializers and put this:

module Paperclip
class Attachment
def default_options
  @default_options ||= {
    :default_url       => "/assets/products/default/:style/Testudo1920.jpg",
    :default_style     => :thumb,
    :storage           => :filesystem,
  }
end
end
end

and then in the model where I am attaching the files, I added attr_accessor:

class Profile < ActiveRecord::Base
has_one :user

attr_accessor :default_url, :default_style

has_attached_file :cover_image,
                :styles => {:thumb => "x70", :header => "x50", :super_thumb => "x28"},
                :default_style => :header,
                :url => "/assets/products/:id/:style/:basename.:extension",  
                :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension",
                :default_url =>  "/assets/products/default/:style/Testudo1920.jpg"

end

Upvotes: 2

Related Questions