mongoid、embedy_many、simple_form

发布于 2024-11-01 08:29:50 字数 790 浏览 1 评论 0原文

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

Bowsersenior

Formtastic with Mongoid嵌入关系

找到了formtastic的解决方案,但我无法对 simple_form formattastic 执行相同操作

= 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

i m looking for a way to manage multiple embedded objects in a form.

found a solution for formtastic by bowsersenior

Formtastic with Mongoid embedded_in relations

but i wasnt able to do the same for simple_form

formtastic:

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

best regards

sample

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阿楠 2024-11-08 08:29:50

不确定这是否有效,但您可能想尝试这样的操作:

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

请记住,您必须在表单显示之前在团队中创建一个新玩家。
在你的控制器(控制器)中:

def new
  @team = Team.new
  8.times { @team.players.new } #for 8 players
end

Not sure if this would work but you might want to try something like this:

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

Just keep in mind that you will have to create a new player in the team before the form will show up.
In your controller(controller):

def new
  @team = Team.new
  8.times { @team.players.new } #for 8 players
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文