ActionView :: Template :: Error(#的未定义方法`events' 你的意思是? eventusers):
1:insert_tag renderer_for(:new)
app / admin / programs.rb:23:in
block (5 levels) in <top (required)>' app/admin/programs.rb:22:in
块(4级)in' app / admin / programs.rb:21:在'{/ p>中的block (3 levels) in <top (required)>' app/admin/programs.rb:17:in
块(2级)中Doubled嵌套表单程序 - &gt;事件 - &gt; eventusers 联合表:events_programs和events_eventusers
模型:
class Program < ApplicationRecord
has_and_belongs_to_many :events, join_table: 'events_programs'
accepts_nested_attributes_for :events, allow_destroy: true
end
class Event < ApplicationRecord
has_and_belongs_to_many :programs
has_and_belongs_to_many :eventusers, join_table: 'events_eventusers'
accepts_nested_attributes_for :eventusers, :allow_destroy => true
end
class Eventuser < ApplicationRecord
has_and_belongs_to_many :events
end
管理员/ programs.rb
ActiveAdmin.register Program do
permit_params :name, events_attributes: [:id, :name, :_destroy, eventuser_ids: []]#s_attributes: [:id, :name, :role, :_destroy]]
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :name
f.inputs do
f.has_many :events, allow_destroy: true do |a|
a.input :events, as: :select, collection: Event.all.uniq.map{|e| e.name} #, :input_html => { :class => 'chosen-select' }
a.inputs "users" do
a.has_many :eventusers do |a|
a.input :eventuser_ids, :as => :select, collection: Eventuser.all#.uniq.map{|e| [e.name, e.role]} , :input_html => { :class => 'chosen-select' }
end
end
end
end
end
f.actions
end
end