如何修复此错误“RailsAdmin中的NoMethodError :: Main#new。未定义方法`多态?'为零:NilClass

时间:2017-07-29 13:32:43

标签: ruby-on-rails ruby activerecord associations rails-admin

model.rb

class Category < ApplicationRecord

  has_many :video_categories
  has_many :videos, :through => :video_categories

end

class VideoCategory < ApplicationRecord
  belongs_to :video
  belongs_to :category
end

class Video < ApplicationRecord
  has_many :video_categories
  has_many :categories, :through => :video_categories
end

我有3个型号。多对多联合。

rails_admin.rb

config.model Video do
  list do
    field :url
    field :title
    field :description
    field :category, :belongs_to_association
    field :views
    field :votes
  end
  edit do
    field :url do
      required true
    end
    field :title do
      required true
    end
    field :description do
      html_attributes do
        {:maxlength => 200,
         :cols => 50}
      end
    end
    field :category, :belongs_to_association
    field :thumbnail
  end
end

以下是浏览器中的错误:

enter image description here

0 个答案:

没有答案