class Ecard include MongoMapper::Document key :family, String key :given, String key :additional, String key :prefix, String key :suffix, String has_many :emails end class Email include MongoMapper::EmbeddedDocument key :pref, Boolean key :email, String end
in the ecards controller
def new
@ecard = Ecard.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @ecard }
end
end
and in my form
<%= form_for(@ecard) do |f| %>
<%= f.label t :family, :scope => :name %><br />
<%= f.text_field :family %><br />
<%= @ecard.emails.each do |email| %>
<%= f.fields_for email, :index => email do |e| %>
<%= e.label :pref %>
<%= e.check_box :pref %>
<%= e.label :email %>
<%= e.text_field :email %>
<% end %>
<% end %>
<% end %>
how to create à new email nested resources ?