0

如何在active_admin表单中显示连接模型的额外属性(在has_many中通过关联)?通过关联导入has_many的Rails活动管理器

f.input :ad_slots 

将只显示ad_slots模式,但我有一个加入其中有一个名为长一个额外的列的表称为stream_slots。我希望能够选择一个ad_slot以及输入持续时间。

这些机型:

#live_stream: 
has_many :stream_slots, :dependent => :destroy 
has_many :ad_slots, :through => :stream_slots 

#ad_slot: 
has_many :stream_slots, :dependent => :destroy 
has_many :live_streams, :through => :stream_slots 

#stream_slot: 
belongs_to :ad_slot 
belongs_to :live_stream 

和stream_slot具有其他两种模式的ID以及所谓的持续时间的附加属性。

谢谢。

- 试过的东西else--

而是链接到ad_slots的,这就是我所做的:

f.has_many :stream_slots do |association| 
    association.inputs do 
    association.input :ad_slot 
    association.input :duration 
    end 

和视频直播活动课,我说:

accepts_nested_attributes_for :stream_slots 

这样窗体显示ad_slots供我选择,以及一个文本字段f或额外的属性,但是,当我尝试保存它时失败。我相信我知道问题是什么,但我不知道如何解决。这是因为stream_slots表中的live_stream_id是空的。如何将其设置为新创建的live_stream? (在一个我现在创建..)

任何帮助,将不胜感激..

回答

1

我得到它的工作,作为问题的问题是,提交表单时,该live_stream_id是空的提及。

所以我只是删除了stream_slot模型中的验证,它表示live_stream_id必须存在并且工作正常。

不知道这是否是最好的办法..但它现在工作。

如果有人有更好的解决方案,请分享。