title: Devise authentication - devise_error_messages! in a view causes "undefined method `errors' for nil:NilClass
body: <p>devise_error_messages! in a view causes</p>
  
  <pre><code>undefined method 'errors' for nil:NilClass
  </code></pre>
  
  <p>after <code>render :new</code> in <code>create</code> method. This started happening after I inherited RegistrationsController from "Devise::RegistrationsController" instead of "ApplicationController". Initial rendering of "new" method does not cause any exceptions.</p>
  
  <p>Overridden registrations controller:</p>
  
  <pre><code>class RegistrationsController &lt; Devise::RegistrationsController
    def create
      begin
        raise I18n.t("registration_disabled") unless registration_enabled?
        ....................
      rescue =&gt; ex
        flash[:alert] = ex.message
        render :new
      end
    end
  end
  </code></pre>
  
  <p>The view registrations/new.html.erb:</p>
  
  <pre><code>&lt;h2&gt;&lt;%= I18n.t("sign_up_title") %&gt;&lt;/h2&gt;
  
  &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt;
      &lt;%= devise_error_messages! %&gt;
  
      &lt;div&gt;&lt;%= f.label :login, I18n.t("the_login") %&gt; &lt;span class="mandatory"&gt;*&lt;/span&gt;&lt;br /&gt;
        &lt;%= f.text_field :login %&gt;&lt;/div&gt;
  
      &lt;div&gt;&lt;%= f.label :password, I18n.t("password") %&gt; &lt;span class="mandatory"&gt;*&lt;/span&gt;&lt;br /&gt;
        &lt;%= f.password_field :password %&gt;&lt;/div&gt;
  
      &lt;div&gt;&lt;%= f.label :password_confirmation, I18n.t("password_confirmation") %&gt; &lt;span class="mandatory"&gt;*&lt;/span&gt;&lt;br /&gt;
        &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt;
  
      &lt;div&gt;&lt;%= f.submit from_admin? ? I18n.t("sign_up_other") : I18n.t("sign_up") %&gt;&lt;/div&gt;
      &lt;p class="mandatory"&gt;* - &lt;%= I18n.t("mandatory_fields") %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  
  &lt;%= render "devise/links" %&gt;
  </code></pre>