On 5 March 2010 13:26, Andy Jeffries <[email protected]> wrote:
> def new
>   �...@content_master = ContentMaster.new
>  �...@content_master.metadata = Metadata.new
>    respond_to do |format|
>      format.html # new.html.erb
>      format.xml  { render :xml => @content_master }
>    end
>  end

I like to leave this to the model where possible - if I *have* to have
an associated object (or if I don't want to do loads of guards like
"@content_master.metadata.attribute unless
@content_master.metadata.nil?") I build/create the associated object
after initialise.

#content_master model
def after_initialize
 metadata ||= Metadata.new
end

... it can cause problems in some cases, but can solve some in others! :-)

(a bit of advice gleaned from the "Refactoring: Ruby Edition" book)

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to