I’m trying to create a chatboard (I call it my BoomBox, each post is
called a “boom”) which appears on every page of a weblog I’m building. I
have a scaffold-built controller called Boom, and the form to post to
the BoomBox is written into my default layout. So, the form can be
viewed from several of my other controllers, in most of their actions.
The form posts to Boom#create.
What I’m having trouble with is handling where the user is returned when
@boom.save fails (for example, failing to include a required field). The
scaffold’s default code renders the Boom#new page, which is nice because
I get all the errors displayed and stuff (validations defined in the
What I would like instead is for the user to be returned to whichever
controller and action the form was submitted from (in a transparent,
HTTP 303 fashion). I’ve tried using redirect_to :back instead, which
works, but the error information is not carried across and displayed as
it would be when I was using render.
What I’ve thought about doing instead is parsing the HTTP_REFERER
environment variable (falling back to the root directory), grabbing the
controller and action from that, and passing those to the render method,
but I can’t help but feel there’s a tidier way of doing what I want.