simple_form
보기에 다형성 연관을 표시하는 방법이 있습니까? Simpleform의 다형성 연관
= simple_form_for(@chat, :html => { :class => "form-horizontal" }, :wrapper => "horizontal", defaults: { :input_html => { class: "form-control"}, label_html: { class: "col-lg-4" } }) do |f|
= f.error_notification
.form-inputs
= f.association :from_user
= f.association :to_user
= f.input :message
= f.association :chattable
.form-actions
= f.button :submit
그리고 모델 아래
가 :class Chat < ActiveRecord::Base
belongs_to :from_user, :foreign_key => 'from_user_id', class_name: 'User'
belongs_to :to_user, :foreign_key => 'to_user_id', class_name: 'User'
belongs_to :chattable, polymorphic: true
validates :from_user, associated: true, presence: true
validates :message, presence: true
end
이 오류 아래 밖으로 던져 :
은 지금까지 나는 아래에있어 많은 옷자락, hawing을 통해
uninitialized constant Chat::Chattable
이것은 포함 문제 일 것 같습니다. Chattable 모델을 보여줄 수 있습니까? – Narfanator
'chattable' 모델이 없습니다. 그것은'polymorphic'이고'chats' 테이블의 일부입니다 –
기다리십시오. 귀하의 모델뿐만 아니라 귀하의 앱이 '채팅'이라고도되어 있습니까? 그것은 당신의 문제 일 수 있습니다. 'Chat' 클래스 이름을 바꾸고'set_table_name' 채팅 이름을 변경하십시오. – Narfanator