Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-4paperclippaperclip-validation

The GEM paperclip saved my images in public/system not in app/assets/images


I am using the gem PaperClip for upload images to my server , but the images are stored in public/system I need to change this ubication to app/assets/images

class User < ActiveRecord::Base
  attr_accessible :email, :name,:photo

  validates :name, :presence => true    
  validates :email, :presence => true
  has_attached_file :photo, :styles => 
           { :medium => "300x300>", :thumb => "100x100>" }

end

I found this tutorial of RailsCasts where these options are declared

has_attached_file :photo, :styles => { :small => "150x150>" },
                  :url  => "/assets/products/:id/:style/:basename.:extension",
                  :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"

validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']

Solution

  • If you look at the PaperClip documentation there its stated:

    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

    So you need to specify the :path variable of has_attached_file to your desired path.

    Hope it helps!