Ruby on Rails when create method fails, render loses local variables

Posted by Jimmy on Stack Overflow See other posts from Stack Overflow or by Jimmy
Published on 2010-06-16T18:13:27Z Indexed on 2010/06/16 18:22 UTC
Read the original article Hit count: 234

Filed under:
|
|

Hey guys I have a simple create method with some validations and whenever the create method fails due to validation errors it re-renders the 'new' action.

The problem is in my new action/view I have a local variable that is established in the action and passed to a partial to render some related information to what the user is creating.

Now when my create action fails and I try to re-render the 'new' action I'm getting the always awesome

undefined method `cover' for nil:NilClass

error.

What is the best way to handle re-establishing my action's local variables on a render instead of redirecting to the action again and the user losing the data they input?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about validation