do you think it's the best solution?

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?