Models:
User
embeds_one :im
accepts_nested_attributes_for :im
IM
embedded_in :user, :inverse_of => :im
Controller:
def new
@user = User.new
@user.build_im
def create
@user = User.new(params[:user])
View:
= form_for @user do |f|
-if @user.errors.any?
#error_explanation
%h2= "#{pluralize(@user.errors.count, "error")} prohibited this
user from being saved:"
%ul
- @user.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
.im
= f.fields_for :im do |fim|
.field
= fim.label :name
= fim.text_field :name
.actions
= f.submit 'Save'
On 14 Sty, 15:04, redhotberry <
redhotbe...@gmail.com> wrote:
> Hey guys! I need your help. I'm so tired with all fail attempts for
> hours.
> I use rails3. I have models "User" and "IM". User embedds IM.
> I need to show form for creating new User with all IM's fields. How to
> do that?
> I have found nice solution here:
http://groups.google.com/group/mongoid/browse_thread/thread/e336576fb...