4

I've been having an issue that I can't seem to fix

3 errors prohibited this user from being saved:

  • Email can't be blank
  • Password confirmation doesn't match Password
  • Password is too short (minimum is 8 characters)

I can't figure out how to get rid of the 3 error prohibited this user from being saved: All I want to display is the errors in bullets. Any ideas on how to go along with this? I'm using Devise, by the way.

Wodin
  • 3,243
  • 1
  • 26
  • 55

3 Answers3

4

I can't figure out how to get rid of the 3 error prohibited this user from being saved

We override the devise helper to give us ultimate control over the errors we wish to show. Here is a helpful resource which shows you how to achieve this

--

Helper

As per the answer by Buck Doyle & the attached resource, you may wish to do this:

#app/helpers/devise_helper.rb
module DeviseHelper
  def devise_error_messages!
     resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
  end
end

This will allow you to change your devise views to include the devise_error_messages! method:

#app/views/devise/registrations/new.html.erb
<%= devise_error_messages! %>
Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • @user302975: I can’t be sure, but I don’t think putting it in `ApplicationHelper` will truly override the Devise helper. That’s why I suggested putting it in an initialiser, and using the name `DeviseHelper`, which will definitely override the existing method. – Buck Doyle May 25 '14 at 15:33
  • So rename it to `DeviseHelper`? @BuckDoyle –  May 25 '14 at 15:33
  • I don't have a `DeviseHelper` only a `application_helper` and a `home_helper` @BuckDoyle –  May 25 '14 at 15:35
  • 1
    Add a *new* file here: `config/initializers/devise_helper_override.rb` and put the `module DeviseHelper` code that I put in my answer. – Buck Doyle May 25 '14 at 15:36
  • I get `
  • Email can't be blank
  • Password can't be blank
  • Email` Any ideas? –  May 25 '14 at 15:46
  • Instead of `|msg| content_tag(:li, msg)`? Sorry for very basic question –  May 25 '14 at 15:57
  • Sorry, this would in your view - instead of just calling `<%= devise_error_messages!`, you could call `<%= raw(devise_error_messages!) %>` – Richard Peck May 25 '14 at 16:12
  • @RichPeck `<%= raw(devise_error_messages!) %>` this doesn't seem to be working for me – bnussey Oct 15 '14 at 14:35
  • Try changing to `resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join.html_safe` – Cam Price-Austin Jan 14 '15 at 23:41