ruby on rails - how to check if parent exists in has many relation -
i have 3 models:
user: has_many :comments video: has_many :comments comment: belongs_to :video, :user
videos/show.html.erb
<%= form_for(@comment, :method => :post ) |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
how can check existence of video before create comment?
this should present validation in comment model.
class comment < activerecord::base validates_presence_of :video
Comments
Post a Comment