Image files are meant to be resized as they are uploaded.
The code ' process resize_to_fill: [800, 350]'
in the uploader file works in production, but not in my development environment. (I use Vagrant)
My file config/initializers/carrierwave.rb
was modified with the following code:
CarrierWave.configure do |config|
if Rails.env.development?
config.cache_dir = '/home/vagrant/uploads_tmp/tmp/uploads'
config.root = '/home/vagrant/uploads_tmp/tmp'
end
end
Because without this code I get the following error (due to using Windows):
Errno::ETXTBSY in Instructor::CoursesController#create
and can't upload at all in development.
My controller action is as follows:
def create
@course = current_user.courses.create(course_params)
if @course.valid?
redirect_to instructor_course_path(@course)
else
render :new, status: :unprocessable_entity
end
end
With the error being thrown on the instance variable assignment line.
Since adding the initializer code, some image files get saved in their original size while others get saved as a mostly blank space (with a small stripe from the image showing at the top). I can not seem to identify anything special about the images in either class! Interestingly, this does not appear to happen when the app is deployed to heroku.
Could someone explain:
1) What is causing the original error, and why does the initializer code fix it.
2) What is going wrong with the image uploads?
EDIT
Since posting my question I found that the files do upload without the code fix in the initializer; in that case the issue would be with accessing the file. I omitted the second line of the error message in my original question, which actually must be key to the issue: Text file busy @ unlink_internal - /vagrant/src/flixter/public/uploads/tmp/1499336954-11657-0001-9160/ecriture.jpg
Here is the full stack trace (original error without the initializer code fix):
Errno::ETXTBSY (Text file busy @ unlink_internal - /vagrant/src/flixter/public/uploads/tmp/1499420789-13682-0001-6708/ben-white-148430.jpg): app/controllers/instructor/courses_controller.rb:10:in 'create' Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/ action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/ action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (5.3ms)
Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/ action_dispatch/middleware/templates/rescues/_trace.html.erb Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/a ction_dispatch/middleware/templates/rescues/_trace.html.erb (2.3ms)
Rendering /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/ action_dispatch/middleware/templates/rescues/_request_and_response.html.erb Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/a ction_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms) Rendered /home/vagrant/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/actionpack-5.0.3/lib/a ction_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (26.1ms)
I still don't know why the initializer code partially fixes the bug!