no implicit conversion of nil into String carrierwave
carrierwave で、動画投稿機能を作成していました。
最初の内は上手く動いていたのですが、
bundle update した後より
no implicit conversion of nil into String
が表示されるようになりました。
carrierwave-version: carrierwave (0.10.0)
- if post.video.present?
.img-responsive.well alt="Responsive image"
= link_to image_tag(post.video_url(:screenshot)), post
- if post.body.present?
p.post_text.well
Application Log
app/uploaders/video_uploader.rb:36:in `dirname'
app/uploaders/video_uploader.rb:36:in `screenshot'
app/views/posts/index.html.slim:37:in `block in _app_views_posts_index_html_slim__885061408226101170_70165504801060'
app/views/posts/index.html.slim:23:in `_app_views_posts_index_html_slim__885061408226101170_70165504801060'
app/uploaders/video_uploader.rb
require 'streamio-ffmpeg'
require 'carrierwave'
class VideoUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# 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 mov wmv mp4 flv avi)
end
version :screenshot do
process :screenshot
def full_filename (for_file = model.logo.file)
"screenshot.jpg"
end
end
def screenshot
tmpfile = File.join(File.dirname(current_path), "tmpfile")
File.rename(current_path, tmpfile)
movie = FFMPEG::Movie.new(tmpfile)
movie.screenshot(current_path + ".jpg", preserve_aspect_ratio: :width)
File.rename(current_path + ".jpg", current_path)
File.delete(tmpfile)
end
end