在rails 4上通过carrierwave gem上传视频

时间:2015-03-09 10:08:48

标签: carrierwave ruby-on-rails-4.1

Hai I am trying to upload a video through rails 4 application locally.

So that I used carrierwave gem in gemfile

Then I generated rails g scaffold video title:string description:string 

rails g uploader Video

add a column for video file parameters to our videos table:

class AddVideoToVideos < ActiveRecord::Migration
def change
add_column :videos, :media, :string

models/videos

class Video < ActiveRecord::Base
mount_uploader :video, VideoUploader
extend FriendlyId
friendly_id :title, use: :slugged
end

end
end

app/controllers/videos_controller.rb

def set_video
@video = Video.friendly.find(params[:id])
end
def video_params
params.require(:video).permit(:title, :description, :media,
:media_cache)
end

views/videos

<%= f.file_field :media %>
<%= f.hidden_field :media_cache %>
<%= f.submit "Save", :class => "btn btn-default" %>


app/uploaders/video_uploader.rb

class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.
id}"
end
def extension_white_list
%w(mp4 ogv avi)
end
end

但是我仍然在控制器中出现错误,例如下面给出但我在哪里没有使用名字但仍然得到同样的错误不知道为什么会这样,请帮助我某人

未定义的方法`name&#39;为零:NilClass  应用程序/控制器/ videos_controller.rb respond_to do | format |       if @ video.save         format.html {redirect_to @video,注意:&#39;视频已成功创建。&#39; }         format.json {render:show,status :: created,location:@video}       其他

0 个答案:

没有答案