Validate presence of polymorphic parent

后端 未结 5 918
耶瑟儿~
耶瑟儿~ 2021-02-19 09:49

I am developing a Rails 3.2 application with the following models:

class User < ActiveRecord::Base
  # Associations
  belongs_to :authenticatable, polymorphic         


        
5条回答
  •  孤城傲影
    2021-02-19 10:15

    In the create action, I had to assign it manually:

    @physician = Physician.new(params[:physician])
    @physician.user.authenticatable = @physician
    

    My problem is a little different (has_many and with different validation), but I think this should work.

提交回复
热议问题