Ошибка: двойные вложенные формы в активном администраторе с habtm - PullRequest
0 голосов
/ 11 июня 2018

ActionView :: Template :: Error (неопределенный метод `events 'для # Вы имели в виду? Eventusers):

1: insert_tag renderer_for (: new)

app /admin / Programs.RB: 23: в блоке block (5 levels) in <top (required)>' app/admin/programs.rb:22:in (4 уровня) в 'app / admin / Programs.rb: 21: в блоке block (3 levels) in <top (required)>' app/admin/programs.rb:17:in (2 уровня) в'

Двойные вложенные формы Программы-> события -> объединенные таблицы пользователей событий: 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

admin / 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
...