Reputation: 3500
I have a SettingsController which allows the users to change the passwords. I am expecting Devise to apply the same validation rules which are applied for passwords elsewhere. In my settings controller, I have the following code :
@user.password = new_pwd
@user.password_confirmation = new_cnf_pwd
if @user.save
format.html { redirect_to settings_home_url }
format.js
else
flash[:error] = "Settings cant be saved"
format.html { redirect_to settings_home_url }
format.js
end
On the SettingsPage, I have :
<%= flash[:error] %>
<%= flash[:warning] %>
<%= flash[:alert] %>
In the form, now the flash[:error] which I have set in the SettingsController is displayed fine. But I want to also display the Devise default errors like "Passwords do not match" on the form. Also, I want to flag the errored fields. Is there a way to do this from a non-devise controller like the one I have ? Thanks... Ved.
Upvotes: 0
Views: 683
Reputation: 12165
Any validation errors for the model will be available in @user.errors
, not flash
.
The Rails Guides: Displaying Validation Errors in the View documentation shows you how to then print them out in your view.
Upvotes: 1