title: Rails + Devise undefined method `errors' for nil:NilClass
body: <p>I'm having issues loading a new registration page using Devise in my rails app.  When I try to load the sign up page, I get the error:</p>
  
  <pre><code>undefined method `errors' for nil:NilClass
  </code></pre>
  
  <p>which seems to be caused by the following line:</p>
  
  <pre><code> &lt;%= devise_error_messages! %&gt;
  </code></pre>
  
  <p>What could I be doing wrong?</p>
  
  <p><strong>routes.rb:</strong></p>
  
  <pre><code>  devise_for :users, :controllers =&gt; {:registrations =&gt; :registrations, omniauth_callbacks: "users/omniauth_callbacks"} 
  
    devise_scope :user do
        post 'registrations' =&gt; 'registrations#create', :as =&gt; 'register'
        post 'sessions' =&gt; 'sessions#create', :as =&gt; 'login'
        delete 'sessions' =&gt; 'sessions#destroy', :as =&gt; 'logout'
    end
  </code></pre>
  
  <p><strong>registrations_controller.rb</strong></p>
  
  <pre><code>class RegistrationsController &lt; Devise::RegistrationsController
    # GET /user/sign_up
    def new
      build_resource({})
      respond_with self.resource
    end
  </code></pre>
  
  <p><strong>The sign up link:</strong></p>
  
  <pre><code>&lt;%= link_to "Sign Up", new_registration_path(resource_name), :class=&gt;"btn btn-mini", :style=&gt;'float:left'%&gt;
  </code></pre>
  
  <p><strong>application_helper.rb (where resource_name is defined)</strong></p>
  
  <pre><code>def resource_name
      :user
  end
  
  def resource
      @resource ||= User.new
  end
  
  def devise_mapping
      @devise_mapping ||= Devise.mappings[:user]
  end
  </code></pre>
  
  <p><strong>the sign up view</strong></p>
  
  <pre><code>&lt;div class="signUpPage"&gt;
  
    &lt;div class="form_container"&gt;
  
          &lt;h3 class="form_heading sign_up"&gt;Sign up&lt;/h3&gt;
  
          &lt;%= semantic_form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt;
  
            &lt;%= devise_error_messages! %&gt;
  
            &lt;div class="formField"&gt;&lt;%= f.label :username, :class=&gt; "label label-info" %&gt;&lt;br /&gt;
            &lt;%= f.text_field :username, :class=&gt; "signup_username", :maxlength=&gt;"15"%&gt;&lt;/div&gt;
            &lt;div class="usernameValidation validation"&gt;Username is already taken&lt;/div&gt;
  
            &lt;div class="formField"&gt;&lt;%= f.label :email, :class=&gt; "label label-info" %&gt;&lt;br /&gt;
            &lt;%= f.email_field :email%&gt;&lt;/div&gt;
            &lt;div class="emailValidation validation"&gt;Email is already taken&lt;/div&gt;
  
            &lt;div class="formField"&gt;&lt;%= f.label :password, :class=&gt;"label label-info" %&gt;&lt;br /&gt;
            &lt;%= f.password_field :password, :class=&gt; "signup_password" %&gt;&lt;/div&gt;
            &lt;div class="passwordValidation validation"&gt;Password must be at least 8 characters&lt;/div&gt;
  
            &lt;div class="formField"&gt;&lt;%= f.label :password_confirmation, :class=&gt;"label label-info" %&gt;&lt;br /&gt;
            &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt;
            &lt;div class="passwordConfirmationValidation validation"&gt;Passwords do not match&lt;/div&gt;
  
            &lt;div&gt;&lt;%= f.submit "Sign up", :class=&gt;"btn btn-info signup_button" %&gt;&lt;/div&gt;
          &lt;% end %&gt;
  
          &lt;%= render "devise/shared/links" %&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the full error message:</p>
  
  <pre><code>NoMethodError in Registrations#new
  
  Showing Website/app/views/devise/registrations/new.html.erb where line #12 raised:
  
  undefined method `errors' for nil:NilClass
  Extracted source (around line #12):
  
  9: 
  10:             &lt;%= semantic_form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), namespace: 'sign_up', html: {id: 'form_user_sign_up'}) do |f| %&gt;
  11:         
  12:               &lt;%= devise_error_messages! %&gt;
  13: 
  14:               &lt;div class="formField"&gt;&lt;%= f.label :username, :class=&gt; "label label-info" %&gt;&lt;br /&gt;
  15:               &lt;%= f.text_field :username, :class=&gt; "signup_username", :maxlength=&gt;"15"%&gt;&lt;/div&gt;
  Rails.root: /Website
  
  app/views/devise/registrations/new.html.erb:12:in `block in _app_views_devise_registrations_new_html_erb___65153715043208623_70149577578880'
  app/views/devise/registrations/new.html.erb:10:in `_app_views_devise_registrations_new_html_erb___65153715043208623_70149577578880'
  app/controllers/registrations_controller.rb:11:in `new'
  </code></pre>