How can you validate the presence of a belongs to association with Rails?

前端 未结 6 1229
夕颜
夕颜 2020-12-28 17:05

Say I have a basic Rails app with a basic one-to-many relationship where each comment belongs to an article:

$ rails blog
$ cd blog
$ script/generate model a         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 18:06

    I fixed this problem adding this follow line to my _comment.html.erb:

    "NEW" if form.object.new_record? %>

    Now, the validation works in stand alone form, and in multi form too.

提交回复
热议问题