Rails : Devise : Remember me not working

 

Processing by Devise::SessionsController#create as HTML
 Parameters: {"utf8"=>"✓", "authenticity_token"=>"5V3s+ASPz7GQ6nE+wXWhQl0jYB25vmRGIt8TpJKggZ8NtOf4Ham2OPp3v9epTifRijsVpxP/ZXKBXz3uDkBtkA==", "user"=>{"email"=>"user@example.com", "password"=>"[FILTERED]"}, "remember_me"=>"on"}
Redirected to http://localhost:3000/

Solution that worked for me

My Form was like:

.form-group
 input#user_email.form-control[type="email" name="user[email]" placeholder="Login ID*"]
 .form-group.user-password
 | <input type="password" class="form-control" minlength="
 = CommonConstants::PASSWORD_MIN_LENGTH
 | " maxlength="
 = CommonConstants::PASSWORD_MAX_LENGTH
 | " id="user_password" name="user[password]" placeholder="Password*"> 
 i.fa.fa-eye
 - if devise_mapping.rememberable?
 .checkbox.checkbox-primary
 input#checkbox3[type="checkbox", name="remember_me"]
 label#custom-check-box[for="checkbox3"]
 | Remember Me
 .form-group.sign-in-button.text-center
 button.btn.btn-lg.btn-danger[type="submit"]
 | Sign In
 = render "devise/shared/links"

I made it

.form-group
 = f.email_field :email, :autofocus => true, class: 'form-control', placeholder: 'Login ID*'
 .form-group.user-password
 = f.password_field :password, class: 'form-control', minlength: CommonConstants::PASSWORD_MIN_LENGTH, maxlength: CommonConstants::PASSWORD_MAX_LENGTH, placeholder: 'Password*'
 i.fa.fa-eye
 - if devise_mapping.rememberable?
 .checkbox.checkbox-primary
 = f.check_box :remember_me, id: 'checkbox3'
 = f.label :remember_me, id: '#custom-check-box'
 | Remember Me
 .form-group.sign-in-button.text-center
 = f.submit 'Sign in', :class => 'btn btn-lg btn-danger'
 | Sign In
 = render "devise/shared/links"

 

 

Note:

I read somewhere to keep the following in `/initializers/devise.rb`

Devise::TRUE_VALUES << ["on"]

But this is found to be use less.. so dont do it

 

Sources:

https://github.com/RailsApps/rails-devise/blob/master/app/views/devise/sessions/new.html.erb

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s