I'm trying to use Fog /Carrierwave/ with Rackspace Cloud Files. I have bunch of uploaded images in my production server. I'm trying to upload these images to Rackspace Cloud Files using below rake task.
desc 'Transfer photos to rackspace'
task :photos => :environment do
photos = Photo.order(created_at: :desc).limit(10)
photos.each do |photo|
if photo.attachment?
photo.attachment.recreate_versions!
photo.save!
else
puts "================================= ATTACHMENT NOT FOUND: ID: #{photo.id}"
end
end
end
But I get following errors:
rake aborted!
undefined method `body' for nil:NilClass
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/storage/fog.rb:227:in `read'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/uploader/cache.rb:77:in `sanitized_file'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/uploader/cache.rb:116:in `cache!'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/carrierwave-0.9.0/lib/carrierwave/uploader/versions.rb:225:in `recreate_versions!'
/home/zeck/code/bee/lib/tasks/bee.rake:9:in `block (4 levels) in <top (required)>'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/activerecord-4.0.1/lib/active_record/relation/delegation.rb:13:in `each'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/gems/activerecord-4.0.1/lib/active_record/relation/delegation.rb:13:in `each'
/home/zeck/code/bee/lib/tasks/bee.rake:7:in `block (3 levels) in <top (required)>'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/bin/ruby_noexec_wrapper:14:in `eval'
/home/zeck/.rvm/gems/ruby-2.0.0-p247#rails-4-1/bin/ruby_noexec_wrapper:14:in `<main>'
It means images not stored in Rackspace Cloud Files. You guys have similar rake task for it? Please share it to me. Or guide me.
Thank you for advice :D
When you change the storage of a CarrierWave uploader from :file to :fog, it loses track of the original uploaded paths of the image files, so methods like recreate_versions! and store! won't be able to find the files to upload.
If you tell CarrierWave the old paths manually, it'll upload them to Cloud Files for you:
desc 'Transfer photos to rackspace'
task :photos => :environment do
photos = Photo.order(created_at: :desc).limit(10)
photos.each do |photo|
if photo.attachment?
# If you've overridden the storage path in the uploader, you'll need to
# use a different path here.
#
# "photo[:attachment]" is used to get the actual attribute value instead
# of the mounted uploader -- the base filename of the attachment file.
path = Rails.root.join('public', 'uploads', photo[:attachment])
unless path.exist?
puts "#{path} doesn't exist. Double check your paths!"
next
end
photo.attachment = path.open
photo.save!
puts "transferred #{photo.id}"
else
puts "================================= ATTACHMENT NOT FOUND: ID: #{photo.id}"
end
end
end
Related
I am trying to save file from a URL and then save it to S3. This is the rake task code that I've written:
require 's3'
require 'open-uri'
task :testing => [:environment] do
aws_object = S3::Service.new(access_key_id: Rails.application.secrets.aws_access_key_id, secret_access_key: Rails.application.secrets.aws_secret_access_key)
bucket = aws_object.buckets.find(Rails.application.secrets.aws_bucket)
url = 'https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png'
downloded_file = open(url)
new_file = bucket.objects.build('twitter.jpg')
new_file.content = (File.read downloded_file)
if new_file.save
puts "Success!"
end
end
But when I run this rake task code above, this is what I got on my terminal:
rake aborted!
S3::Error::ResponseError: S3::Error::ResponseError
/Users/ryzal/Sites/test/lib/tasks/testing.rake:17:in `block in <top (required)>'
/Users/ryzal/.rbenv/versions/2.3.1/bin/bundle:23:in `load'
/Users/ryzal/.rbenv/versions/2.3.1/bin/bundle:23:in `<main>'
Tasks: TOP => testing
(See full trace by running task with --trace)
I've checked all my S3 details and all are correct. Can somebody help?
Thanks!
I've finally solved this and this is how I did it:
1) I use aws-sdk-ruby gem instead of s3 gem
2) I refer S3 documentation here and renew my code to this:
require 'aws-sdk-s3'
require 'open-uri'
task :testing => [:environment] do
s3 = Aws::S3::Resource.new(region: Rails.application.secrets.aws_region)
obj = s3.bucket(Rails.application.secrets.aws_bucket).object("any_unique_key_you_want_such_as_email_or_username")
url = 'https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png'
file = open(url)
obj.put(body: file, acl: "public-read")
puts "URL is: #{obj.public_url}"
end
In a Rails 4 app, I want precompiled assets to have copies of some assets to be available with a non fingerprinted filename. The app is deployed on Heroku.
I have the following rake task in place:
namespace :app do
task :nonfingerprint_assets => :environment do
manifests = Rails.application.config.assets[:precompile]
manifests = manifests.slice(1, manifests.length)
assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
assets.each do |file|
next if File.directory?(file) || file !~ regex
source = file.split('/')
source.push(source.pop.gsub(regex, '.'))
non_digested = File.join(source)
if manifests.any? {|m|
if m.is_a? Regexp
m.match non_digested
else
m.ends_with?(non_digested)
end
}
puts "** copy source: #{file}"
puts "** copy destination: #{non_digested}"
FileUtils.cp(file, non_digested)
end
end
end
end
Rake::Task['assets:precompile'].enhance do
puts "Invoke nonfingerprint_assets"
Rake::Task['app:nonfingerprint_assets'].invoke
end
This rake task is working fine on my local machine even in production environment. It creates a file in public/assets/application.js which is the copy of the same file with a digest in its name.
When I deploy this code to heroku I get the following error message which I don't understand:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_
locales = false to avoid this message.
Invoke nonfingerprint_assets
** copy source: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application-51d1660b66655782ab137ee98c789fdd.js
** copy destination: /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
rake aborted!
No such file or directory - /tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/public/assets/application.js
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:26:in `block (3 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `each'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:9:in `block (2 levels) in <top (required)>'
/tmp/build_48b86bff-83f9-4d21-8b21-712c1baef811/lib/tasks/production.rake:45:in `block in <top (required)>'
Tasks: TOP => app:nonfingerprint_assets
(See full trace by running task with --trace)
Please help me to understand what's going on.
I've an uploader where I've implement the #filename method to get a custom and unique filename but it looks like this method is ignored before saving the file (I'm uploading to rackspace with the fog gem)
Here is the uploader:
class MyImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
...
def filename
if original_filename.present?
"#{secure_token}.#{file.path.split('.').last.downcase}"
else
super
end
end
...
private
def secure_token
var = :"##{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
end
And here is a test in the console (I'm testing an issue with large filenames that I thought was solved with the custom #filename method):
1.9.3-p392 :002 > f = File.open('/Users/myuser/Desktop/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png')
=> #<File:/Users/myuser/Desktop/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.png>
1.9.3-p392 :003 > my_model_instance.image = f
Errno::ENAMETOOLONG: File name too long - /Users/myuser/app/tmp/uploads/20130509-1723-16769-8458/thumb_lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat4lolcat.png
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1371:in `initialize'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1371:in `open'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1371:in `block in copy_file'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1370:in `open'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1370:in `copy_file'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:477:in `copy_file'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:396:in `block in cp'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1531:in `fu_each_src_dest0'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
from /Users/myuser/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/fileutils.rb:395:in `cp'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/sanitized_file.rb:205:in `copy_to'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/cache.rb:121:in `block in cache!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/cache.rb:112:in `cache!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/versions.rb:231:in `block in cache_versions!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/versions.rb:216:in `each'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/versions.rb:216:in `cache_versions!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:18:in `each'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/uploader/cache.rb:112:in `cache!'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/mount.rb:315:in `cache'
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/gems/carrierwave-0.6.2/lib/carrierwave/mount.rb:173:in `image='
from /Users/myuser/.rvm/gems/ruby-1.9.3-p392#app/bundler/gems/carrierwave-mongoid-28a9b718d42b/lib/carrierwave/mongoid.rb:39:in `image='
So I think that I need to modify the filename before being saved in order to get the custom filename fully working because actually the file only is rename after being uploaded to Rackspace (only if the filename it's not so large)
The upload is exploding during the caching step (which happens locally) rather than the saving step (which happens in fog). Reading the source, it looks like carrierwave has a method you can override to do just this: full_original_filename
If the problem you're trying to solve is to make the cached filename shorter, the following may work. If you want to change that filename later, you'll need to use the official solution for that in addition.
MAX_FILENAME_LENGTH = 64 # arbitrary limit, your milage may vary
def full_original_filename
filename = super
return filename if !filename.present?
extension = File.extname(filename)
basename = File.basename(filename, extension)[0...MAX_FILENAME_LENGTH]
basename + extension
end
Using CarrierWave and Amazon S3, I'm able to store images from local files, but when I try to store them from certain url, I get 'TypeError: can't convert nil into String'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:149:in `join'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:149:in `cache_path'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:121:in `block in cache!'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/cache.rb:112:in `cache!'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/carrierwave-0.5.8/lib/carrierwave/uploader/store.rb:56:in `store!'
from (irb):5
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/bashar/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
This is the code I'm trying
require 'open-uri'
image = "open(image_url)
#object.image.store!(file)
obviously #object holds the Uploader image and it's been working fine using local file systems. I tried to add a
def root
Rails.root.join 'public/'
end
to my uploader as well with no luck.
Any idea?
To tell carrier wave to download a remote url, you use this syntax:
#object.remote_image_url = "http://www.example.com/file.png"
#object.save
I am using Rails 3.1 RC and Carrierwave 0.5.4. Don't know if this is an issue with 3.1.
I verified that the path and file exists (http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif) in my S3 bucket.
When I do:
Photo.first.update_attributes!(:job_state => 'processing', :remote_attachment_url => 'http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif')
Error I get:
Errno::ENOENT: No such file or directory - /Users/Chris/Sites/site_name/tmp/uploads/20110603-1813-612-6936/small_test.gif
Why is Carrierwave trying to access the local dir instead of S3?
My initializer looks like:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => APP_CONFIG['amazon_access_key_id'], # required
:aws_secret_access_key => APP_CONFIG['amazon_secret_access_key'] # required
}
config.fog_directory = 'bucket_name' # required
config.fog_host = 'http://cdn.site_name.com' # optional, defaults to nil
config.fog_public = true # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
My uploader class looks like:
# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/users/#{model.user.id}/#{model.class.to_s.underscore}s/#{model.id}"
end
# Create different versions of your uploaded files:
version :small do
process :resize_to_fill => [53,53]
end
version :medium do
process :resize_to_fill => [106,106]
end
version :large do
process :resize_to_fill => [212,212]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# https://github.com/jnicklas/carrierwave/wiki
# Heroku has a read-only filesystem, so uploads must be stored on S3 and cannot be cached in the public
# directory. You can work around the caching limitation by setting the cache_dir in your Uploader classes
# to the tmp directory.
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end
Full stack trace:
Errno::ENOENT: No such file or directory - /Users/Chris/Sites/site_name/tmp/uploads/20110603-1827-5843-3673/small_test.gif
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `initialize'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `open'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `read'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:230:in `store'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:79:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:59:in `block in store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `each'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `store_versions!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `each'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!'
... 16 levels...
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:246:in `save!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:168:in `block in update_attributes!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:166:in `update_attributes!'
from (irb):5
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:44:in `start'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136#railspre/gems/railties-3.1.0.rc1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>
In my uploader class, if I remove the versions, the upload succeeds without any errors.
Anyone coming across the same problem?
Hmmmm, I don't know exactly what the problem is, but I switched my gem file from:
gem 'carrierwave', :git => 'http://github.com/jnicklas/carrierwave.git'
to
gem 'carrierwave', '0.5.4'
The problem seems to have gone away. There is something definitely wrong with the master version...
Hope this helps someone who comes across the same issue on Rails 3.1 RC and Carrierwave.
Its your code here
def cache_dir
"#{Rails.root}/tmp/uploads"
end
Your app is using that for processing the images.
Following command should do the trick. On Ubuntu it is like:
sudo apt-get install imagemagick