Rails3.2 Devise3.1 で Users を作ったものの、 current_user が nil だし、 app/users/edit で NoMethodError `errors' for nil:NilClass な時

はまったのでメモ。

Deviseのセットアップが終わって、Login/Logoutを試してOK、EditでユーザのPassword,Emailを変更しようとしたとき
 app/users/edit

ActionView::Template::Error (undefined method `errors' for nil:NilClass):
    1: <h2>Edit <%= resource_name.to_s.humanize %></h2>
    2: 
    3: <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
    4:   <%= devise_error_messages! %>
    5: 
    6:   <div><%= f.label :email %><br />
    7:   <%= f.email_field :email, :autofocus => true %></div>
  app/views/devise/registrations/edit.html.erb:4:in `block in _app_views_devise_registrations_edit_html_erb___169669084_79062200'
  app/views/devise/registrations/edit.html.erb:3:in `_app_views_devise_registrations_edit_html_erb___169669084_79062200'

devise_error_messages! でなんかおかしなことになっているらしい。
あと、current_user が Nil

このあたりを探したのですがよくわからず。
http://stackoverflow.com/questions/4101641/rails-devise-handling-devise-error-messages

そんなとき、セットアップでApplicationController.rbに書き入れたこれを消してみよう。

Comment out your current_user, helper_method in
ApplicationController.rb

#  def current_user  
#    @current_user ||= User.find(session[:user_id]) if session[:user_id]  
#  end  
#    
#  helper_method :current_user

Then current_user , users/edit work!

ApplicationControllerのヘルパー記述を消したらすべてうまくいったよ!って言ってくれてる人を
StackOverflowで見かけたので。

また、user_signed_in? が動かず、 signed_in? なら動きました。

お試しをば。

ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]
Rails3.2.14
Devise3.1

Gem list
actionmailer (4.0.0, 3.2.14)
actionpack (4.0.0, 3.2.14)
activemodel (4.0.0, 3.2.14)
activerecord (4.0.0, 3.2.14)
activerecord-deprecated_finders (1.0.3)
activerecord-jdbc-adapter (1.3.0)
activerecord-jdbcmysql-adapter (1.3.0)
activerecord-mysql2-adapter (0.0.3)
activeresource (3.2.14)
activesupport (4.0.0, 3.2.14)
acts_as_paranoid (0.4.2)
arel (4.0.0, 3.0.2)
atomic (1.1.14, 1.1.13)
bcrypt-ruby (3.1.2, 3.0.1)
bigdecimal (1.1.0)
builder (3.1.4, 3.0.4)
bundler (1.3.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.3)
daemon_controller (1.1.5)
devise (3.1.0)
erubis (2.7.0)
execjs (2.0.1)
faraday (0.8.8)
hashie (2.0.5)
hike (1.2.3)
httpauth (0.2.0)
i18n (0.6.5)
io-console (0.3)
jdbc-mysql (5.1.25)
journey (1.0.4)
jquery-rails (3.0.4)
json (1.8.0, 1.5.4)
jwt (0.1.8)
libv8 (3.16.14.3)
mail (2.5.4)
mime-types (1.25)
minitest (4.7.5, 2.5.1)
multi_json (1.8.0, 1.7.9)
multipart-post (1.2.0)
mysql2 (0.3.13)
oauth2 (0.8.1)
omniauth (1.1.4)
omniauth-facebook (1.4.1)
omniauth-oauth2 (1.1.1)
orm_adapter (0.4.0)
passenger (4.0.14)
polyglot (0.3.3)
rack (1.5.2, 1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.14)
rails3_acts_as_paranoid (0.2.5)
railties (3.2.14)
rake (10.1.0, 0.9.2.2)
rdoc (3.12.2, 3.9.4)
ref (1.0.5)
rubygems-update (2.0.7)
sass (3.2.10)
sass-rails (3.2.6)
sprockets (2.10.0, 2.2.2)
sprockets-rails (2.0.0)
sqlite3 (1.3.8)
therubyracer (0.12.0)
thor (0.18.1)
thread_safe (0.1.3, 0.1.2)
tilt (1.4.1)
treetop (1.4.15)
tzinfo (0.3.37)
uglifier (2.2.1)
warden (1.2.3)