gpt4 book ai didi

mongoid、embedy_many、simple_form

转载 作者:行者123 更新时间:2023-12-04 06:28:54 27 4
gpt4 key购买 nike

我正在寻找一种方法来管理表单中的多个嵌入对象。

找到了 bowsersenior 的 formtastic 解决方案

Formtastic with Mongoid embedded_in relations

但我无法对 simple_form 做同样的事情

形式:

= semantic_form_for @team do |form|
= @team.players.each do |player|
= form.inputs :for => [:players, player] do |player_form|
= player_form.input :name

此致

样本
class Team
include Mongoid::Document
field :name, :type => String
embeds_many :players
end

class Player
include Mongoid::Document
embedded_in :team, :inverse_of => :players
field :name, :type => String
field :active, :type=> Boolean # checkboxes
end

最佳答案

不确定这是否可行,但您可能想尝试以下操作:

= simple_form_for @team do |form|
= f.input :name
= f.simple_fields_for @team.players do |player_form|
= player_form.input :name

请记住,在表格出现之前,您必须在团队中创建一个新玩家。
在您的 Controller ( Controller )中:
def new
@team = Team.new
8.times { @team.players.new } #for 8 players
end

关于mongoid、embedy_many、simple_form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5685546/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com