Validation failed Class must exist

后端 未结 8 1503
面向向阳花
面向向阳花 2020-12-13 17:30

I have been (hours) trouble with associations in Rails. I found a lot of similar problems, but I couldn\'t apply for my case:

City\'s class:

class Ci         


        
相关标签:
8条回答
  • 2020-12-13 18:04

    Try the following:

    belongs_to :city, optional: true
    

    According to the new docs:

    4.1.2.11 :optional

    If you set the :optional option to true, then the presence of the associated object won't be validated. By default, this option is set to false.

    0 讨论(0)
  • 2020-12-13 18:14
    params.require(:user).permit(:name, :citys_id)
    

    It's a mistake, isn't it? (citys_id vs city_id)

    0 讨论(0)
提交回复
热议问题