Classier solution for file uploads for Rails, Sinatra and other Ruby web frameworks carrierwaveuploader/carrierwave · GitHub carrierwave - classier solution for file uploads for rails, sinatra and other ruby web frameworks

Displaying a Carrierwave filename in the view

I am trying to display the filename of a Carrierwave attachment in a Rails erb template. The following does not work:

<%= @page.form.filename %>

This seems in line with the documentation. Is some additional step needed?

My page model looks like this:

class Page < ActiveRecord::Base

  mount_uploader :form, FormUploader


The form uploader looks like this:

class FormUploader < CarrierWave::Uploader::Base

  storage :file

  def store_dir

  def extension_white_list


Source: (StackOverflow)

Validate image size in carrierwave uploader

All uploads should be at least 150x150 pixels. How to validate it with Carrierwave?

Source: (StackOverflow)

Undefined Method Scale In CarrierWave

I'm trying to use this code in my uploader

  version :thumb do
    process :scale => [50, 50]

and I get an error saying

undefined method `scale' for #<#<Class:0x235b680>:0x0fb4c8>

I'm using Carrierwave with MiniMagick. How can I fix this error?

Source: (StackOverflow)

Configure Environment to Use File System Locally and Amazon on Heroku

I am not sure how to configure the environment such that Carrier Wave will use the local file storage when running the app locally (development) and s3 after i load to heroku (production)

in Development storage :file

in Production storage :s3

Source: (StackOverflow)

rspec testing carrierwave - newbie

I'm making a rails 3.1 app using carrierwave to upload files to aws s3. I've followed the instructions on the carrierwave github repository and am now able to upload files to my aws bucket. It's the testing that got me stuck. Over the last two days I've been googling and revising, using all the other Q&A's I've found but am finally crying 'mama.' Here's what I've got:


storage :fog

def store_dir


if Rails.env.test? or Rails.env.cucumber?
  CarrierWave.configure do |config| = :file
    config.enable_processing = false


require 'spec_helper'
require 'support/fog_helper'
require 'carrierwave/test/matchers'

describe ImageFileUploader do
  include CarrierWave::Test::Matchers

  before do
    ImageFileUploader.enable_processing = true
    @user = Factory(:user, :email => "")
    @uploader =, Factory(:image))!("#{Rails.root}/tmp/uploads/#{Rails.env}/images/"))

  after do
    ImageFileUploader.enable_processing = false

  context 'the tiny version' do
    it "should scale down a landscape image to be exactly 50 by 50 pixels" do
      @uploader.tiny.should have_dimensions(50, 50)


Factory.define :image do |image|
  include ActionDispatch::TestProcess

  image.date_taken            "Sun, 09 Oct 2011"
  image.time_taken            "2000-01-01 03:41:00 UTC"
  image.image_file            fixture_file_upload('spec/support/test_images/audi.png', 'image/png')
  image.taken_by              "John Doe"
  image.collection            "N/A"
  image.comments              "Beautiful day!"
  image.association   :user


While my /public/uploads/tmp/ is getting filled up with 'tiny' (and other versions) of the images whose generation I am testing, the tests continue to fail with the following error message:

1) ImageFileUploader the tiny version should scale down a landscape image to be exactly 50 by 50 pixels

 Failure/Error: @uploader =, Factory(:image))
   Expected(200) <=> Actual(404 Not Found)
     request => {:expects=>200}
     response => #<Excon::Response:0x0000010569f928 @body="", @headers={}, @status=404>
 # ./spec/uploaders/image_file_uploader_spec.rb:11:in `block (2 levels) in <top (required)>'

I know that the above means that rspec isn't finding my testing bucket. Anyone have any thoughts about what I'm doing wrong?

would be super grateful for any new leads.

UPDATE: 10/11/11 The file upload works but I've stalled in figuring out how to get test involving the images to pass. In the short term, I will use a placeholder image as I flesh out the rest of my app and return to this later. I'll post a further update once I figure this out. (Do leave any thoughts if you have any insights, however.)

Source: (StackOverflow)

Carrierwave; multiple uploaders or just one?

I have a post model and a podcast model. Both models have an attribute titled: image. I'm using one Carrierwave uploader (named ImageUploader) to handle both models. I have two questions before I go into production.

Dumb question:

Is it ok to use the same uploader for two different models when they both have the same attribute name for their file attachements? sorry if it seems obvious

Main question:

I want to create three versions of each blog post image (thumb, large, sepia) and only 1 version of each podcast image (thumb).

Do I need to use two uploaders now or can I namespace with the one that I'm already using?

Again it probably seems obvious. I could probably have written the second uploader in the time its taken me to ask these questions

Source: (StackOverflow)

Factory with carrierwave upload field [duplicate]

This question already has an answer here:

Hello i need to build up Factory for my model, for example

Factory.define :farm do |f| { :name }
  f.harvest '3'
  f.offers 'Random'
  f.latitude '43'
  f.longitude '-70'
  f.about 'We rocks!'
  f.logo { :logo } # this doesn't work

For now im just pass string "#{n}.jpg" into my logo field and this dont work, how to evalute this field? Im using CarrierWave for uploading.

Source: (StackOverflow)

Uploading a remote file url from Rails Console with Carrierwave

I just wanted to know how one would go about uploading a remote file url using Carrierwave in the Rails console.

I tried the following without any luck. I presume it's not processing the Uploader?

user = User.first
user.remote_avatar_url = ""

Many thanks

Source: (StackOverflow)

Deleting files in ruby

I'm using the carrierwave gem to upload files. I have built a system for users to flag images as inappropriate and for admins to remove the images. From what I can tell, calling destroy on the image will only remove the path name from the tabel. Is there a way to have ruby actually remove the file itself? Or should rails be automatically removing the file when I destroy the image path?

Source: (StackOverflow)

Carrierwave files with Capistrano

I'm using rails 3.2 with asset and carrierwave for upload some images, they store in /public/uploads/photo/..... but when I do a cap:deploy (with capistrano) my current directory application doesn't contain the files I uploaded, because capistrano make a new version ....

=== Update ===

After all I use this :

inside :deploy namespace

   task :symlink_uploads do
     run "ln -nfs #{shared_path}/uploads  #{release_path}/public/uploads"

and after:

after 'deploy:update_code', 'deploy:symlink_uploads'

=== Re Update ===

The solution of @tristanm is the best way to solve this.

Source: (StackOverflow)

Seeding file uploads with CarrierWave, Rails 3

I'm trying to seed a database in Rails 3 with images using CarrierWave, however nothing I try seems to work short of having to upload them all by hand.

pi = => product)
pi.image =, 'test.jpg'))
pi.store_image! # tried with and without this
product.product_images << pi!

Anybody know how to seed using CarrierWave at all?

Source: (StackOverflow)

Renaming uploaded files with Carrierwave

I'm using Carrierwave to upload files, and I have it working.

My issue is attempting to change the name of the uploaded file.

In the generated uploader.rb there is a method I think I should be using

def filename
   "something.jpg" if original_filename
   basename = "what"+orginal_filename if original_filename, works
   basename = (0...8).map{65.+(rand(25)).chr}.join if original_filename  # will create a random name for each version, e.g. the orginal, the thumb, and the filename in the db, useless

I can't seem to access items like 'extension' or 'content_type' in sanitized_file.rb, so this is a bit beyond my current skill level right now.

Any suggestions or exercises for doing this, i.e. generate filename for an uploaded file that works as well as the carrierwave default (do nothing, but does carry on to each version)? Seems like it should be simple enough but I've stumbled over this.

Source: (StackOverflow)

Reprocessing images in Carrierwave

Let's say my model has an image with :thumb and the client wants :tiny and :nano thumbnails.

How do I reprocess all the existing images using a rake task?

I've found a rask that I thought would do it but it's giving me errors.

Source: (StackOverflow)

Undefined method `image_will_change!' for CarrierWave on Heroku

I have a simple model that mounts a Carrierwave uploader. Everything works fine in development, but I get an undefined method "image_will_change!" error on heroku.

class Receipt < ActiveRecord::Base
  mount_uploader :image, ImageUploader

class ImageUploader < CarrierWave::Uploader::Base
  storage :fog
  def store_dir

I have the cache_dir set appropriately as well according to the Carrierwave Wiki.

receipt.image = "public/images/test.jpg" #works fine in development, fails in heroku

Source: (StackOverflow)

Carrierwave - Resizing images to fixed width

I'm using RMagick and want my images to be resized to a fixed width of 100px, and scale the height proportionally. For example, if a user were to upload a 300x900px, I would like it to be scaled to 100x300px.

Source: (StackOverflow)