ruby on rails 投稿一覧に動画を表示させたいが表示できない
myページの自分の投稿一覧になると動画が表示されません。
何故動画が表示されないのでしょうか?分かる方教えて頂きたいです。
posts/index.html.erb
<div class="main posts-index">
<div class="container">
<% @posts.each do |post| %>
<div class="posts-index-item">
<div class="post-left">
<img src="<%= "/user_images/#{post.user.image_name}" %>">
</div>
<div class="post-right">
<div class="post-user-name">
<%= link_to(post.user.name, "/users/#{post.user.id}") %>
</div>
<div class="post-user-names">
<%= link_to(post.content, "/posts/#{post.id}") %>
</div>
<div class="posts-user-names">
<%= video_tag(post.video.to_s, "/posts/#{post.id}", height: "35%", width: "50%", controls: true, autobuffer: true )%>
</div>
</div>
</div>
<% end %>
</div>
</div>
posts_controller.rb
before_action :authenticate_user
before_action :ensure_correct_user, {only: [:edit, :update, :destroy]}
def index
@posts = Post.all.order(created_at: :desc)
end
def show
@post = Post.find_by(id: params[:id])
@user = @post.user
@post = Post.find(params[:id])
@comments = @post.comments
@comment = Comment.new
end
def new
@post = Post.new
end
def create
@post = Post.new(
content: params[:content],
user_id: @current_user.id,
)
if params[:post].present?
@post.video = params[:post][:video]
end
if @post.save
flash[:notice] = "投稿を作成しました"
redirect_to("/posts/index")
else
render("posts/new")
end
end
def edit
@post = Post.find_by(id: params[:id])
end
def update
@post = Post.find_by(id: params[:id])
@post.content = params[:content]
if @post.save
flash[:notice] = "投稿を編集しました"
redirect_to("/posts/index")
else
render("posts/edit")
end
end
def destroy
@post = Post.find_by(id: params[:id])
@post.destroy
flash[:notice] = "投稿を削除しました"
redirect_to("/posts/index")
end
def ensure_correct_user
@post = Post.find_by(id: params[:id])
if @post.user_id != @current_user.id
flash[:notice] = "権限がありません"
redirect_to("/posts/index")
end
end
end
0