前提・実現したいこと
rails で動画投稿アプリを作成中です。
現在、投稿完了するとMYSQLにはvideoカラムにデーターが保存されているのですが、
再生するページ(index.html.erbなど)での再生ができない状態です。
他のカラムの値はMYSQLに保存され、表示されるべきページに表示されています。
該当のソースコード
コントローラー
class ProductsController < ApplicationController before_action :move_to_index, except: [:index,:show] def index # @products = Product.includes(:user).order("created_at DESC") # @bob = Product.where(stylegenre_id: 1) @bob_style = Product.where(stylegenre_id: 1).order("id DESC").limit(3) @short_style = Product.where(stylegenre_id: 2).order("id DESC").limit(3) @mid_style = Product.where(stylegenre_id: 3).order("id DESC").limit(3) @semlong_style = Product.where(stylegenre_id: 4).order("id DESC").limit(3) @long_style = Product.where(stylegenre_id: 5).order("id DESC").limit(3) @superlong_style = Product.where(stylegenre_id: 6).order("id DESC").limit(3) @hairset_style = Product.where(stylegenre_id: 7).order("id DESC").limit(3) # @stylegenres = Product.all.order("created_at DESC") end def new @product = Product.new end def create Product.create(product_params) redirect_to root_path end def edit @product = Product.find(params[:id]) end def update product = Product.find(params[:id]) if product.user_id == current_user.id product.update(link_url:product_params[:link_url],shop_name:product_params[:shop_name],video:product_params[:video],text:product_params[:text],item_id:product_params[:item_id],cosme:product_params[:cosme],stylegenre_id:params[:stylegenre_id],color_id:params[:color_id],perm_id:params[:perm_id],user_id: current_user.id) end redirect_to root_path end def destroy product = Product.find(params[:id]) if product.user_id == current_user.id product.delete redirect_to root_path end end def show @product = Product.find(params[:id]) @item = Item.find(@product.item_id) @color = Color.find(@product.color_id) @perm = Perm.find(@product.perm_id) @stylegenre = Stylegenre.find(@product.stylegenre_id) end def search @products = Product.includes(:user).page(params[:page]).per(9).order("created_at DESC") end private def product_params params.require(:product).permit(:link_url,:shop_name,:video,:text,:stylest_name,:cosme).merge(stylegenre_id:params[:stylegenre_id],color_id:params[:color_id],perm_id:params[:perm_id],item_id: params[:item_id],user_id: current_user.id) end def move_to_index redirect_to action: :index unless user_signed_in? end end
ビュー(index)
.genres-link .bob-style ボブ .bob-contents - @bob_style.each do |style| .one-index-contents .shop_name-index 店名: = style.shop_name .video-index-product = video_tag style.video_url.to_s,loop: true, controls: true, width: 300,class:"mv" %i.far.fa-clipboard.index-icon = link_to '詳細',"/products/#{style.id}" .short-style ショート .short-contents - @short_style.each do |style| .one-index-contents .shop_name-index 店名: = style.shop_name .video-index-product = video_tag style.video_url.to_s,loop: true, controls: true, width: 300,class:"mv" %i.far.fa-clipboard.index-icon = link_to '詳細',"/products/#{style.id}",class:"stylename"
ビュー(new)
.one-new-product = form_for @product do |f| %h3 掲載する .new-form = f.label :店名(必須),class:"out-label" = f.text_field :shop_name,class:"text-box" .error-new-1 .new-form = f.label :説明文(必須),class:"form-label" = f.text_field :text,class:"text-box" .error-new-2 .new-form = f.label :動画(必須),class:"video-label" = f.file_field :video,class:"video-form" .error-new-3 .new-form = f.label :スタイリスト名(必須),class:"form-label" = f.text_field :stylest_name,class:"text-box" .error-new-4 .new-form = f.label :コスメ,class:"out-label" = f.text_field :cosme,class:"text-box" .error-new-9 .new-form = f.label :リンク,class:"out-label" = f.text_field :link_url,class:"text-box" .error-new-10 .new-item-form = f.label :スタイル(必須),class:"select-label" %select.stylename-select-box{name: "stylegenre_id"} %option{value: ""} ---- %option{value: 1} ボブ %option{value: 2} ショート %option{value: 3} ミディアム %option{value: 4} セミロング %option{value: 5} ロング %option{value: 6} スーパーロング %option{value: 7} ヘアセット .error-new-5 .new-item-form = f.label :アイテム(必須),class:"select-label" %select.items-select-box{name: "item_id"} %option{value: ""} ---- %option{value: 1} ストレートアイロン %option{value: 2} コテ32mm %option{value: 3} コテ28mm %option{value: 4} コテ18mm %option{value: 5} コテ16mm %option{value: 6} ヘアゴム %option{value: 7} なし .error-new-6 .new-item-form = f.label :カラー(必須),class:"select-label" %select.items-select-box{name: "color_id"} %option{value: ""} ---- %option{value: 1}
モデル
class Product < ApplicationRecord mount_uploader :video, VideoUploader mount_uploader :image, ImageUploader belongs_to :user belongs_to :item belongs_to :color belongs_to :perm belongs_to :stylegenre validates :text, presence: true validates :shop_name, presence: true validates :stylest_name, presence: true validates :video, presence: true end
モデル(video_uploader)
class VideoUploader < CarrierWave::Uploader::Base def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end
試したこと
モデルのアソシエーションの確認
あなたの回答
tips
プレビュー