我的video
个对象上有标签。我可以通过我的表单创建新视频时提交标签,但是我们不会出现在我的视频展示页面,视频索引或视频编辑表单上,这让我觉得它们并没有出现在数据库中,但我认为它们已经存在。我不清楚我错过了什么或做错了什么。
class Video < ActiveRecord::Base
after_create { validates_presence_of :user, :post }
belongs_to :user
belongs_to :post
has_many :comments
validates :title, presence: true
acts_as_taggable
end
<%= will_paginate @videos %>
<div class="" id="tag_cloud">
<% tag_cloud Video.tag_counts.sort { |x, y| x.name <=> y.name }, %w[s m l] do |tag, css_class| %>
<%= link_to tag.name, tag_path(tag.name), class: css_class %>
<% end %>
</div>
<div class="">
<% @videos.each do |video| %>
<div class="">
<%= link_to video.title, video_path(video) %></br >
<%= content_tag(:iframe, nil, src: "//www.youtube.com/embed/#{video.embed_id}") %>
<p>Created by: <%= video.user.username %>, at: <%= video.created_at.strftime("%e, %b, %Y, %H:%M:%S %p") %></p>
<% unless video.comments.last.nil? %>
<%= video.comments.last.body %>
<% end %>
<p>
Tags: <%= raw video.tag_list.map { |t| link_to t, tag_path(t) }.join(", ") %>
</p>
<% end %>
</div>
</div>
<div class="">
<% if current_user == @post.user || current_user.admin %>
<h3>Add video</h3>
<div class="">
<%= form_for [@post, @video] do |f| %>
<div class="">
<%= f.label(:title, "Video Title") %></br >
<%= f.text_field(:title) %>
</div>
<div class="">
<%= f.label(:url, "Video Url") %></br >
<%= f.text_field(:url) %>
</div>
<div class="">
<%= f.label(:tag_list, "Tags (separated by commas)") %></br >
<%= f.text_field(:tag_list, multiple: true) %>
</div>
<div class="">
<%= f.submit("Submit Video") %>
</div>
<% end %>
</div>
<% end %>
</div>
<div class="video-show">
<%= @video.title %>
<%= content_tag(:iframe, nil, src: "//www.youtube.com/embed/#{@video.embed_id}") %>
<p>
Tags: <%= @video.tag_list %>
</p>
<% if current_user == @video.user %>
<%= link_to "Edit Video", edit_video_path(@video) %> |
<%= link_to "Delete Video", video_path(@video), method: :delete, data: { confirm: "Are you sure?" } %> |
<% end %>
<% if current_user == @video.user %>
<%= link_to("Back to Log", post_path(@post)) %> |
<% end %>
<%= link_to("Back to Index", videos_path) %>
</div>
def index
if params[:tag]
@videos = Video.tagged_with(params[:tag]).page(params[:page]).per_page(10).order(created_at: "desc")
else
@videos = Video.all.page(params[:page]).per_page(10).order(created_at: "desc")
end
end
private
def video_params
params.require(:video).permit(
:title,
:url,
:tag_list,
)
end