Saving the images Dimensions (width and height) in Paperclip?

Just for the sake of completeness, even though previous answers already show good enough suggestions. You can utilize Paperclip event handlers instead of Rails callbacks. In this case, size will be recalculated only when image changes. (If you’re using S3 for storage, this can save quite some time) has_attached_file :image, :styles => … after_post_process :save_image_dimensions … Read more

unit test in rails – model with paperclip

Adding file to a model is dead simple. For example: @post = Post.new @post.attachment = File.new(“test/fixtures/sample_file.png”) # Replace attachment= with the name of your paperclip attachment In that case you should put the file into your test/fixtures dir. I usually make a little helper in my test_helper.rb def sample_file(filename = “sample_file.png”) File.new(“test/fixtures/#{filename}”) end Then @post.attachment … Read more

Saving files using Paperclip without upload

I have a rake task that loads images (client logos) from a directory directly onto parperclip. You can probably adapt it to your needs. This is my simplified Client model: class Client < ActiveRecord::Base LOGO_STYLES = { :original => [‘1024×768>’, :jpg], :medium => [‘256×192#’, :jpg], :small => [‘128×96#’, :jpg] } has_attached_file :logo, :styles => Client::LOGO_STYLES, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)