dsp_099
dsp_099

Reputation: 6121

How to prefill input fields on model error?

I have resources :campaigns defined in routes.rb.

If I create a form_for @campaign in /campaigns/new.html.erb (campaigns#new), create appropriate fields, and then submit it if there's an error saving the model in campaigns#create, if I redirect the browser back to the campaigns#new, the form fields appear empty.

I remember there being some trick to it, but I can't seem to Google it because I'm weak on nomenclature.

Upvotes: 1

Views: 142

Answers (1)

Ismael
Ismael

Reputation: 16730

In your create action instead of redirecting just render the 'new' page so your @campaign value is set when rendering the form.

Upvotes: 3

Related Questions