When you use the new Renderer Rails 5, middleware fails. Devise uses Warden and sets it as an env ['warden'] environment variable, and thus it is not present when the renderer is called. This is the reason you get this error.
To make it work, on your controller, simply use before_action for the controller action #, which will be displayed to set and pass the instance variable needed for the view.
If you need to check if the user has been logged in or use current_user in the rendered view:
class ExamplesController < ApplicationController before_action :user_logged_in?, only: :show before_action :set_user, only: :show def show
Then in the View ExampleController # show:
# views/examples/show.html.erb <%= "Online" if @user_logged_in %> <%= @user.full_name %>
Hope that helps
Meene
source share