[英]polymorphic nested form active_admin rails
我在網上尋找了許多解決方案,但似乎找不到答案。
我有一個鏈接到許多其他表的表鏈接的多態關聯。
這是我的模型有點簡化:
links.rb
class Links < ActiveRecord::Base
belongs_to :linkable, polymorphic: true
end
events.rb
class Event < ActiveRecord::Base
has_many :links, as: :linkable
accepts_nested_attributes_for :links
end
這是管理員表格
events.rb
ActiveAdmin.register Event do
form do |f|
f.has_many :links do |link_f|
link_f.inputs "links" do
link_f.input :url
end
end
f.actions
end
end
這是我的schema.rb中的內容
create_table "links", force: true do |t|
t.string "url"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "linkable_id"
t.string "linkable_type"
end
它引發了我這樣的錯誤: 未初始化的常量Event :: Link
我似乎找不到問題,這讓我發瘋了...
似乎缺少某種關系或某些東西,但我找不到它。
非常感謝您能提供的所有幫助!
我認為問題出在您命名模型的方式上。 模型總是聲明為單數實體,而不是復數實體。
你應該:
links.rb
重命名為link.rb
events.rb
為event.rb
class Links < ActiveRecord::Base
到class Link < ActiveRecord::Base
看看是否有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.