我在ActiveModel,Event上使用form_for,它有一个哈希:参与者和哈希:电子邮件。每个哈希的键只是一个数字,表示每个人的“id”,值是他们的名字:参与者和他们的电子邮件:电子邮件。例如,event.emails[1]
是人event.participants[1]
的电子邮件。我的表格如下:
= form_for @event, :url => input_constraints_path, html: {:method => :post } do |f|
- @event.participants.keys.each do |num|
%div
%div.inline-block
= f.fields_for :participants do |p|
= p.label num
= p.text_field num
%div.inline-block
= f.fields_for :emails do |e|
= e.label "email"
= e.email_field num
%br
= submit_tag "Next"
我的ActiveModel看起来像这样(使用rails 3所以我无法使用ActiveModel :: Model):
class Event
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations
include ActiveModel::Conversion
attr_accessor :participants, :emails
...
end
出于某种原因,当我使用现有的@event ActiveModel对象时,它不会预先填充字段。有什么建议吗?