Несколько свойств HABTM с ActiveAdmin и Rails 4: данные не сохранены

У меня есть следующие модели:

class Programme < ActiveRecord::Base

  has_and_belongs_to_many :nationalities, class_name: 'Nation', join_table: 'nationalities_nations'
  has_and_belongs_to_many :destinations, class_name: 'Nation', join_table: 'destinations_nations'

  accepts_nested_attributes_for :nationalities
  accepts_nested_attributes_for :destinations

end

и

class Nation < ActiveRecord::Base

  has_and_belongs_to_many :nationality_programmes, class_name: 'Programme', join_table: 'nationalities_nations'
  has_and_belongs_to_many :destination_programmes, class_name: 'Programme', join_table: 'destinations_nations'

  accepts_nested_attributes_for :nationality_programmes
  accepts_nested_attributes_for :destination_programmes

end

В активном администраторе у меня есть следующая конфигурация, которая предварительно правильно выбирает любые существующие сохраненные ссылки на страны (см. снимок экрана).

ActiveAdmin.register Programme do

  permit_params :title,
            destinations_ids: [:id],
            nationalities_ids: [:id]


  form do |f|
    f.actions
    f.inputs 'Countries / Regions' do
      f.input :nationalities, :as => :select, :input_html => {:multiple => true}
      f.input :destinations, :as => :select, :input_html => {:multiple => true}
      f.input :title
    end
    f.actions
  end
end

Однако, когда я выбираю другие страны, форма успешно сохраняется, но ссылки не сохраняются.

Это моя схема:

ActiveRecord::Schema.define(version: 20140522131219) do

  create_table "destinations_nations", force: true do |t|
    t.integer "programme_id", null: false
    t.integer "nation_id",    null: false
  end

  create_table "levels_programmes", force: true do |t|
    t.integer "programme_id", null: false
    t.integer "level_id",     null: false
  end

  create_table "nationalities_nations", force: true do |t|
    t.integer "programme_id", null: false
    t.integer "nation_id",    null: false
  end

  create_table "nations", force: true do |t|
    t.string   "slug",       limit: 2
    t.string   "name"
  end

  create_table "programmes", force: true do |t|
    t.string   "title"
  end

end

введите здесь описание изображения

Обновление: эта проблема опубликована на странице active_admin#3196, которая теперь закрыт, благодаря помощи Грегорио.


person Besi    schedule 22.05.2014    source источник


Ответы (1)


Я заставил это работать, изменив

permit_params :title,
        destinations_ids: [:id],
        nationalities_ids: [:id]

to

permit_params :title,
        destination_ids: [],
        nationality_ids: []
person Gregorio Setti    schedule 06.06.2014
comment
Где вы нашли документацию по вашему решению? Как вы к этому пришли? - person Defoncesko; 20.04.2015
comment
Я только что посмотрел логи и увидел Unpermitted parameter: destination_ids Итак, activeadmin пытался отправить этот параметр вместо destinations_ids: [:id] - person Gregorio Setti; 21.04.2015