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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -