Rails ActiveAdmin未经许可的参数has_many通过关系

时间:2018-01-24 10:29:34

标签: ruby-on-rails activeadmin has-many-through

我有一个关于has_may的关系

class Isicclase < ActiveRecord::Base
  belongs_to :isic_grupo
end

class Configuracion < ActiveRecord::Base
   has_many :configuracion_isicclases
   has_many :isicclases, through: :configuracion_isicclases
   accepts_nested_attributes_for :configuracion_isicclases, :allow_destroy => true
end

class ConfiguracionIsicclase < ActiveRecord::Base
  belongs_to :configuracion
  belongs_to :isicclase
end

和第二个模型的ActiveAdmin寄存器(Configuracion)

ActiveAdmin.register Configuracion do
  config.filters = false
  menu parent: '☰ Entorno', label: 'Configuración', priority: 1

  actions :all, except: [:destroy]
 permit_params :comercial, :social, :polcorreo, :personal, :bienvenida, :localizacion, :galleta, :slogan1, :slogan2, :logo, :logo_file_name, :privacidad, :aviso_legal, :locale, :proteccion_de_datos, configuracion_isicclases_attibutes: [:id, :configuracion_id, :isicclase_id, :_destroy] 
   form do |f|
      f.actions
       f.semantic_errors *f.object.errors.keys
      f.inputs "Configuración" do
         tabs do
            tab 'Empresa' do
                  f.has_many :configuracion_isicclases, heading: false,  :allow_destroy => true do |deg|
                    # deg.input :isicclase
                    deg.input :isicclase, label: 'Código ISIC', :collection => Isicclase.all.map{|x|[x.codigo + "-" + x.titulo,x.id]}, include_blank: false 
                  end

                  f.input :comercial
                  f.input :social
                  f.input :polcorreo
                  f.input :slogan1
                  f.input :slogan2
                  f.input :logo, :as => :file, :hint => image_tag(f.object.logo.url(:icon)) 
            end 
.......

end

当我尝试通过配置创建一个新的寄存器configuracion_isicclases时,我在日志文件中获得了一个不允许的paremeter错误

Unpermitted parameter: configuracion_isicclases_attributes

日志文件中的参数是

Parameters: configuracion"=>{"configuracion_isicclases_attributes"=>{"0"=>{"isicclase_id"=>"417", "_destroy"=>"0", "id"=>"1"}, "1"=>{"isicclase_id"=>"3", "_destroy"=>"0", "id"=>"2"}, "2"=>{"isicclase_id"=>"1"}}, "comercial"=>"Costiña",......}

1 个答案:

答案 0 :(得分:1)

请尝试此解决方案,如果有任何sigular或复数问题,请更正

你在configuracions.rb

permit_params :comercial, :social, :polcorreo, :personal, :bienvenida, :localizacion, :galleta, :slogan1, :slogan2, :logo, :logo_file_name, :privacidad, :aviso_legal, :locale, :proteccion_de_datos, :isicclas_ids => [] 

f.input :isicclases, as: :select, :collection => Isicclase.all.map{|x|[x.codigo + "-" + x.titulo,x.id]}, include_blank: false