Có cách nào để hiển thị liên kết đa hình trong chế độ xem simple_form
không?Hiệp hội đa hình trong Simpleform
Cho đến nay tôi đã có dưới đây:
= 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
Và dưới đây mô hình:
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
này ném ra dưới đây lỗi:
uninitialized constant Chat::Chattable
Điều này có vẻ như có thể là sự cố bao gồm. Bạn có thể cho chúng tôi thấy mô hình Có thể thích được không? – Narfanator
Tôi không có mô hình 'chattable'. It's 'polymorphic' và nó là một phần của bảng' chats' –
Đợi đã. Ứng dụng của bạn có tên là "Trò chuyện" cũng như mô hình của bạn không? Đó có thể là vấn đề của bạn. Hãy thử đổi tên lớp 'Trò chuyện' và sau đó là' set_table_name "trò chuyện" '. – Narfanator