2014-02-22 31 views
1

保存初始模型時無法使ActiveAdmin保存關聯的模型。ActiveAdmin關聯在保存中不更新其屬性

我有兩個模型,如下所示:

# app/models/account.rb 
class Account < ActiveRecord::Base 
    has_one :endpoint, inverse_of :account, class_name: 'Abcd::Endpoint' 
    accepts_nested_attributes_for :endpoint 

    delegate :access_key, to: :endpoint 
end 

# app/models/abcd/endpoint.rb 
class Abcd::Endpoint < ActiveRecord::Base 
    attr_accessible :account_id, :access_key 

    belongs_to :account 
end 

我ActiveAdmin文件看起來像:

# app/admin/account.rb 
Activeadmin.register Account do 

    form do |f| 
    f.inputs do 
     f.input :name 
    end 

    f.inputs title: 'endpoints', for: [:endpoint. f.object.endpoint || Endpoint.new] do |nested_form| 
     nested_form.input :access_key, 
     label: 'Access Key', 
     as: :string 
    end 
    f.actions 
    end 

    show do |account| 
    row 'endpoint has access_key' do 
     account.access_key 
    end 
    end 
end 

當我點擊「更新賬戶」賬戶被更新,但端點 模型不會更新。看起來端點屬性不是 被髮送到端點模型。

有誰知道如何讓端點模型得到更新與其 屬性或我需要修復?

+0

shoudn't它來代替nested_form.input nested.form.input –

+0

對不起,這是我的一個錯字。我在app/admin/account.rb文件中的代碼是nested_form.input。更新了問題。 –

+0

如果用'f.object.build_endpoint'替換'Endpoint.new',會發生什麼? –

回答

0

試試看

form do |f| 
    f.inputs "Account" do 
     f.input :name 
    end 

    f.inputs do 
     f.has_one :endpoint, inverse_of :account, class_name: 'Abcd::Endpoint' do |nested_form| 
     nested_form.input :access_key, 
     nested_form.label('Access key') 
     end 
    end 
    f.actions 
end 
+0

這給了我兩個問題。 1)它在inverse_of上的錯誤,我可以通過將冒號添加爲「inverse_of:」來解決,2)未定義的方法「has_one」,我無法弄清楚如何解決。 –

+0

@JamesTesta實際上我從http://www.activeadmin.info/docs/5-forms.html看過f.has_many,所以我認爲has_one也應該工作。 –

+0

看看https://github.com/gregbell/active_admin/issues/59#issuecomment-21467793 –

相關問題