公告
财富商城
积分规则
提问
发文
2019-02-10 14:15发布
闹够了就滚
I need a plugin for "Upload Videos" in a rails application.
Can anyone give me an idea on how to do it?
You can also use carrierwave gem
carrierwave
Add in your Gemfile: gem 'carrierwave'
gem 'carrierwave'
Run bundle install
bundle install
Create an uploader for uploading video using carrierwave generator.
rails g uploader video
It creates file video_uploader.rb in uploaders directory
video_uploader.rb
uploaders
Create a migration in model where you want attach the video or image, be careful with the migration name it should be like add_{column}_to_{model}
add_{column}_to_{model}
rails g migration add_video_to_post video:string
Migrate database
Run rake db:migrate
rake db:migrate
Add uploader to the model
class Post < ActiveRecord::Base mount_uploader :video, VideoUploader end
Add video parameter in PostController
class PostController < ApplicationController . . . def post_params params.require(:post).permit(:name,:video) end end
Add file attachment field in _forml.html.erb which is in views/posts
_forml.html.erb
views/posts
<%=f.file_field :video%>
To view/stream the video
<% @posts.each do |post|%> <%= post.name %> <%= video_tag post.video_url.to_s :controls =>true %> <%end%>
for more information carrierwave gem https://github.com/carrierwaveuploader/carrierwave and video tutorial http://railscasts.com/episodes/253-carrierwave-file-uploads
Try paperclip gem, very popular for this purpose
Even more specific, I created a Rails gem that works specifically with videos: https://rubygems.org/gems/paperclip-ffmpeg
最多设置5个标签!
You can also use
carrierwave
gemAdd in your Gemfile:
gem 'carrierwave'
Run
bundle install
Create an uploader for uploading video using carrierwave generator.
rails g uploader video
It creates file
video_uploader.rb
inuploaders
directoryCreate a migration in model where you want attach the video or image, be careful with the migration name it should be like
add_{column}_to_{model}
rails g migration add_video_to_post video:string
Migrate database
Run
rake db:migrate
Add uploader to the model
Add video parameter in PostController
Add file attachment field in
_forml.html.erb
which is inviews/posts
To view/stream the video
for more information carrierwave gem https://github.com/carrierwaveuploader/carrierwave and video tutorial http://railscasts.com/episodes/253-carrierwave-file-uploads
Try paperclip gem, very popular for this purpose
Even more specific, I created a Rails gem that works specifically with videos: https://rubygems.org/gems/paperclip-ffmpeg