Hi! I fallowed this topic
http://groups.google.com/group/mongoid/browse_thread/thread/f294f524d91d884f/efa83dc6f6b627c5?lnk=gst&q=form#efa83dc6f6b627c5
and realized such code
class Company
include Mongoid::Document
include Mongoid::Timestamps
field :title, :type => String
field :rating, :type => Float
embeds_one :company_profile
end
class CompanyProfile
include Mongoid::Document
field :phone, :type => String
field :www, :type => String
field :public_email, :type => String
field :working_hours, :type => String
embedded_in :company, :inverse_of => :company_profile
end
Companies controller method:
# GET /companies/new
# GET /companies/new.xml
def new
@company = Company.new
@company.build_company_profile
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @company }
end
end
And the _form template:
<%= form_for(@company) do |f| %>
<% if @company.errors.any? %>
.... error handling
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :rating %><br />
<%= f.text_field :rating %>
</div>
<% f.fields_for :company_profile do |builder| %>
<p>
<%= builder.label :public_email, "Public email" %>
<%= builder.text_field :public_email %><br />
<%= builder.label :www, "WWW" %>
<%= builder.text_field :www %><br />
</p>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
It doesn't works and nested form does not displaying! When it tried to
use <%=debug :company_profile %>, it printed only
"--- :company_profile"
Could you help me?