I have:
class Shop < ActiveRecord::Base
 has_many :documents, :dependent => :restrict
 has_many :roles, :dependent => :restrict
 accepts_nested_attributes_for :documents
 accepts_nested_attributes_for :roles
the shop _form is:
= simple_form_for(@shop) do |shop_f|
 = render ''shared/error_messages'', :object => @shop
 = render :partial => ''document_fields_form'', :locals =>
{ :f =>
shop_f } if @shop.new_record? or @document
 = field_set_tag t(''shop'') do
   .inputs
     = shop_f.input :name
.............
I want to create a new document only if I''m inserting a new shop
record or if @document is defined.
Shop_controller e'':
def new
   @shop = Shop.new
   @document = @shop.documents.build
   new!
 end
In questo modo quando creo un nuovo Shop creo anche un nuovo Document
relativo, poi...
def edit
   @shop = Shop.find(params[:id])
   @document = @shop.documents.build if params[:dlg114]
   edit!
end
But this way if the document is not valid I can''t see document fields
because it isn''t a new record and @document is not defined.
Can you suggest a better way to do this?
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.