All threads / How do construct remember me after login ?
Ask A Question


You’re not receiving notifications from this thread.

How do construct remember me after login ?

Minimalstics asked in Rails

In my login-in form in have a params 'remember me' . How do i read its value in controller . biggest problem i m facing right now.

<div class="row">
  <div class="col-md-offset-3 col-md-7" style="text-align: center;">
    <h2><b>Log In</b></h2>
<div class="row">
  <div  class="col-md-offset-3 col-md-7">
    <%= form_with url: sessions_path do |form| %>
      <div class="form-group">
          <%= form.label :email %>
          <%= form.text_field :email, class: "form-control" %>
      <div class="form-group">
          <%= form.label :password %>
          <%= form.text_field :password, class: "form-control" %>
      <div class="field">
          <%= form.label :"remember_me" %>
          <%= form.check_box :remember_me %>

     <%= form.submit "Login", class: "btn btn-primary btn-block" %>
    <% end %>

Sessions Controoler

class SessionsController < ApplicationController
    def new

  def create
     user = User.find_by_email(params[:email])
     if user && user.authenticate(params[:password])

       log_in user
       if params[:rememeber_me] == 1
               auth_token = SecureRandom.urlsafe_base64
                user.authentication_token = auth_token
                cookies.permanent[:auth_token] = auth_token
                user.authentication_token = nil
                cookies.permanent[:auth_token] = nil
       redirect_to user
     else[:danger] = 'Invalid email/password combination'
       render 'new'

   def destroy
    #  @current_user = nil
    #  reset_session
       redirect_to root_path


Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 70,078+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.