我有一个用户,帐户和预订模型。帐户和预订belongs_to :user以及用户has_one :account和has_many :bookings
问题是,我可以运行方法User.create_account,但是当我运行User.create_booking时,它会给我一个NoMethodError: undefined methodcreate_booking'`
你知道为什么会发生这种事吗?
发布于 2013-06-26 20:16:53
之所以定义create_account,是因为它是一个has_one关联。对于has_many,您可能需要bookings.create。
有关关联方法的完整列表,请参阅http://guides.rubyonrails.org/association_basics.html#has_many-association-reference。
https://stackoverflow.com/questions/17319752
复制相似问题