You probably meant that second redirect to be a render. Your code
would fail if the save actually happened since you would then both
render and redirect.
Typically the pattern is
def new
@foo = Foo.new
end
def create
@foo = Foo.new(params[:foo])
if @foo.save
redirect_to :controller => 'somewhere'
else
render :action = 'new'
end
end
why do you do the @foo=Foo.new twice? I understand the second once,
since you are doing the create and using the params to receive it, but
isn't the other one not needed?
why do you do the @foo=Foo.new twice? I understand the second once,
since you are doing the create and using the params to receive it, but
isn't the other one not needed?
The first one is for the new page, which still needs an instance of foo to render the form (so everything will be blank). You could also set defaults.
Fred