views:

113

answers:

2

Hi There.

How can I make a sticky form in rails?

Thanks

+1  A: 

Rails scaffolds do this automatically, right? Your form behavior shouldn't be departing much from theirs.

When you do <% form_for @user %>, all of the user's attributes are automatically filled in to that form. When your user fails to validate and does not save, the form is displayed, and @user still has all of the attributes that the user originally submitted; therefore, the form fields fill themselves out as intended.

Matchu
A: 

If upon submission it does not pass validation you want to send the user back to the same action without resetting it. To achieve this you need the following code in your controller:

render :action => 'new'

or

render :action => 'edit'

These 2 would typically be in the create and update method respectively.

allesklar