user984621
user984621

Reputation: 48513

Rails 3 - validation rule with redirecting to own URL

I have a registration form and on this model is set a validation rule for checking, if the email format is right and if is entered email unique. This works fine. But then I have after registration can user change his email address - in other form (settings page) - and when he set bad email format or set the email, that is already taken, so thanks to validation rules will be not saved this email to database, but with the validation error will the user redirected to the registration form.

And my question is, how can I change the redirect - I would like to redirect the user back to the settings page.

Upvotes: 0

Views: 196

Answers (1)

rpechayr
rpechayr

Reputation: 1292

Go to your #update method in the appropriate controller (the one called by the form submission) and change the redirection from here. It might be that your controller uses the respond_withmacro. In this case just change it to

respond_to do |format|
    if @registration.save #say your model is @registration for example
      format.html
    else
      redirect_to settings_path #The regular situation here is usually render :action => "edit"

Upvotes: 1

Related Questions