Personally I normally have actions that postback to themselves, which
saves having to deal with this problem, but in order to get this to
work, you will have to call the action as well as the render - for
example to alias ''index'' to ''list'':
def index
list
render :action => ''list''
end
So you''d have to put a call to ''action'' right before
your call to render:
if @new_release.save
redirect_to :action => ''create_tracks''
else
index
render :action => ''index''
end
Cheers,
Dan
On 8/25/05, Hunter Hillegas
<lists-HAWAbpnI61OZ1JSuHaJ1sQC/G2K4zDHf@public.gmane.org>
wrote:> In an action called index I have some code that grabs some objects from the
> database to populate a select form helper. This works great.
>
> Problem is that if I try to save the form generated by the index action and
> validation fails, I run into trouble.
>
> My save process looks like this:
>
> if @new_release.save
> redirect_to :action => ''create_tracks''
> else
> render :action => ''index''
> end
>
> If validation fails and render gets called, Rails attempts to render the
> template for index without calling the action, which gives a 500 because
the
> select form helper doesn''t have any data (the data is fetched in
the index
> action).
>
> If I do a redirect instead of a render it seems to each anything in the
> flash, including my error messages.
>
> So, what is the best practice here?
>
> Thx.
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>