create action gives NoMethodError and nil.each

I have two actions, create and index. The index view has a list of
find(:all) objects and also a form for creating new objects. If the
form is valid upon creation, everything works (it is redirected to the
index page with the new object listed). If validation fails, I get the
error. My questions is, is it possible to do something like this?

Sometimes this happens when you have code like this:

def create
  @foo =[:foo])
  if @foo.valid?
    flash[:success] = 'Foo created.'
    redirect_to :action => 'show', :id => @foo
    render :action => 'new'

If it works on a successful create but not on a render to 'new' then
you are likely loading objects in the 'new' action that is not loaded
in 'create'.


def new
  @foo =
  @bars = Bar.find(:all)

When you render the 'new' template from the create action you may need
to reload the @bars (in this example).

Hope this helps.

That didn't even cross my mind! Makes perfect sense. Thanks!