1
我有3種型號:如何檢查是否存在父在擁有衆多關係
User: has_many :comments
Video: has_many :comments
Comment: belongs_to :video, :user
視頻/ show.html.erb
<%= form_for(@comment, :method => :post) do |f| %>
<%= f.text_area :body %>
<%= f.hidden_field :video_id, :value =>"4" %>
<%= f.submit "submit" %>
<% end %>
comments_controller
def create
@comment = Comment.new(params[:comment].merge(:user_id => current_user.id))
@comment.save
end
哪有我在創建評論之前檢查視頻是否存在?
非常感謝! – ma9 2011-02-17 17:29:22