2014-05-22 2 views
12

मैं निम्नलिखित मॉडल:ActiveAdmin और रेल 4 के साथ एकाधिक HABTM गुण: डेटा सहेजा नहीं

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 

enter image description here

अद्यतन: ग्रेगोरियो की मदद करने के लिए active_admin#3196 जो अब बंद है, धन्यवाद पर इस समस्या का पार तैनात

यह मेरा स्कीमा है।

उत्तर

20

मैं तुम्हें कहाँ अपने समाधान बारे में दस्तावेज़ प्राप्त था कि यह

permit_params :title, 
     destination_ids: [], 
     nationality_ids: [] 
+0

को

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

बदलकर काम किया? आप उस पर कैसे आए? – Defoncesko

+1

मैं सिर्फ लॉग पर एक नज़र ले लिया, और 'unpermitted पैरामीटर देखा: destination_ids' तो activeadmin ' destinations_ids के बजाय उस पैरामीटर भेजने के लिए कोशिश कर रहा था: [: id] 'प्रतिक्रिया –

+0

ठीक धन्यवाद , धन्यवाद – Defoncesko

संबंधित मुद्दे