我有两个belongs_to
关联到同一模型,然后在
simple_form
= f.association :from_user
= f.association :to_user
在chats
表中,我有from_user_id
和to_user_id
用户模型
has_many :from_user_chats, :foreign_key => :from_user_id, :class_name => 'Chat'
has_many :to_user_chats, :foreign_key => :to_user_id, :class_name => 'Chat'
聊天模型
class Chat < ActiveRecord::Base
belongs_to :from_user, class_name: 'User'
belongs_to :to_user, class_name: 'User'
belongs_to :chattable, polymorphic: true
end
然而,这让我失误:
undefined method `from_user_id' for #<Chat:0xcf283e0>
有原因吗?
Bactrace:
block in #<Class:0xd660bf0>#_app_views_chats__form_html_haml__904465522_69002796
app/views/chats/_form.html.haml, line 5
#<Class:0xd660bf0>#_app_views_chats__form_html_haml__904465522_69002796
app/views/chats/_form.html.haml, line 1
#<Class:0xd660bf0>#_app_views_chats_new_html_haml___186355583_68493228
app/views/chats/new.html.haml, line 3