Topic: Persist error_messages_for(:object) across a request

Is it possible to hang on to the error_messages_for(:object) for the duration of a redirect_to? I know the convention is to use render :action instead of redirect_to when there are errors saving a model, but in this case, the form is generated by a different controller than the one saving the model. What would be the Rails Way to pass the errors over to the other controller action?

Last edited by jed.hurt (2006-11-11 21:45:57)

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?

Re: Persist error_messages_for(:object) across a request

Stick it in the flash?

flash[:error] would work  in this case.

vinnie - rails forum admin

Re: Persist error_messages_for(:object) across a request

You probably want to keep the values the user entered as well. You can try putting the entire model in the flash - this should save the errors, entered values, etc.

Railscasts - Free Ruby on Rails Screencasts

Re: Persist error_messages_for(:object) across a request

ryanb wrote:

You probably want to keep the values the user entered as well. You can try putting the entire model in the flash - this should save the errors, entered values, etc.

That does sound like a good solution, but I figured out that I really should just follow standard suit and keep the action in the same controller in this case. I'm finding out more and more that Convention Kool-Aid is usually the sweetest flavor.

I thought about how mothers feed their babies with tiny little spoons and forks, so I wondered what do Chinese mothers use. Toothpicks?