我正在使用Ruby on Rails开发一个博客,我想使用carrierwave gem上传视频。我使用了此有用的帖子来关注:Upload Video in a rails application
我已经尝试通过添加来Rails Carrierwave Video Uploader,但这似乎没有什么不同。
video_uploader.rb:
class VideoUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
new.html.erb:
<%= f.label :video %><br>
<%= f.file_field :video %>
show.html.erb:
<% @posts.each do |post|%>
<%= video_tag post.video_url.to_s :controls =>true %>
<% end %>
创建新帖子时,由于出现以下错误,我无法单击“显示”
Showing C:/Sites/Application/app/views/posts/show.html.erb where line #10 raised:
undefined method `each' for nil:NilClass
Line 10 :<% @posts.each do |posts|%>
Line 11: <%= video_tag post.video_url.to_s :controls =>true %>
Line 12: <% end %>
我已将视频保存在资产/视频中。通过应用程序上传后,它们将被保存在public / uploads / posts / video / 1 / vid1.mp4