0

When trying to signing in/up with devise, the error below occurs.

undefined local variable or method `flash' for #<Devise::SessionsController:0x00000000009b78>
devise (4.7.1) app/controllers/devise_controller.rb:159:in `set_flash_message'
devise (4.7.1) app/controllers/devise_controller.rb:166:in `set_flash_message!'
devise (4.7.1) app/controllers/devise/sessions_controller.rb:20:in `create'
actionpack (6.1.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.1.1) lib/abstract_controller/base.rb:228:in `process_action'
actionpack (6.1.1) lib/action_controller/metal/rendering.rb:30:in `process_action'

extracted source:

      flash.now[key] = message if message.present?
    else
      flash[key] = message if message.present? # This throws an error.
    end

Here are the files I'm using.

# models/user.rb
class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  has_many :posts, inverse_of: :author, dependent: :destroy
end

# routes.rb
Rails.application.routes.draw do
  devise_for :users

  resources :users, only: [:index, :show]
  resources :posts, only: [:index, :show, :create]

  root 'posts#index'

end

I tried devise versions 4.7.1 to 4.7.3.

versions

ruby '2.7.2'
gem 'rails', '~> 6.1.1'
gem 'devise', '~>4.7.1'
alfai
  • 1
  • 1

0 Answers0