title: undefined method `downcase' for nil:NilClass ruby on rails
body: <pre><code>class SessionsController &lt; ApplicationController
  
      def new
  
      end
  
      def create
          user = User.find_by(email: params[:session][:email].downcase)
          if user &amp;&amp; user.authenticate(params[:session][:password])
              session[:user_id] = user.id
              flash[:success] ="You have successfully logged in"
              redirect_to users_path(user)
  
          else
              flash.now[:danger] = "Invalid email or password"
              render 'new'
  
          end
  
      end
  
      def destroy
          session[:user_id] = nil
          flash[:success] = "Successfully logged out"
          redirect_to root_path   
  
      end
  end
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SIDBJ.png" rel="nofollow noreferrer">This is my error</a>
  <a href="https://i.stack.imgur.com/SIDBJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SIDBJ.png" alt="This is my error"></a></p>
  
  <p>here is the routes.rb</p>
  
  <pre><code>get 'login', to: 'sessions#new'
  
  post 'login', to: 'sessions#create'
  
  delete 'logout', to: 'sessions#destroy'
  </code></pre>