Setting session length with Devise

Look in config/initializers/devise.rb. There are a lot of configuration settings including config.timeout_in. The default in my version is 30 minutes. You can also set it on the model itself: class User < ActiveRecord::Base devise :timeoutable, :timeout_in => 15.minutes You can now also set the timeout dynamically.

undefined method ‘devise’ for User

Add devise to your application Gemfile and install it by running bundle install. After this, you should run the following generator command: rails generate devise:install This generator will install an initializer your_application/config/initializers/devise.rb which consists of all the Devise’s configuration options. You missed the above mentioned step which is why the devise configurations are not set … Read more

Rails 3 – Can Active_admin use an existing user model?

Yes you can do that, when running the generator skip the user model creation: rails generate active_admin:install –skip-users Then in your config/initializers/active_admin.rb : # == User Authentication # # Active Admin will automatically call an authentication # method in a before filter of all controller actions to # ensure that there is a currently logged … Read more

Rails 4 + Devise: Password Reset is always giving a “Token is invalid” error on the production server, but works fine locally.

Check the code in app/views/devise/mailer/reset_password_instructions.html.erb The link should be generated with: edit_password_url(@resource, :reset_password_token => @token) If your view still uses this code, that will be the cause of the issue: edit_password_url(@resource, :reset_password_token => @resource.password_reset_token) Devise started storing hashes of the token, so the email needs to create the link using the real token (@token) rather … Read more

Devise limit one session per user at a time

This gem works well: https://github.com/devise-security/devise-security Add to Gemfile gem ‘devise-security’ after bundle install rails generate devise_security:install Then run rails g migration AddSessionLimitableToUsers unique_session_id Edit the migration file class AddSessionLimitableToUsers < ActiveRecord::Migration def change add_column :users, :unique_session_id, :string, limit: 20 end end Then run rake db:migrate Edit your app/models/user.rb file class User < ActiveRecord::Base devise :session_limitable … Read more

Rails & Devise: How to render login page without a layout?

You can subclass the controller and configure the router to use that: class SessionsController < Devise::SessionsController layout false end And in config/routes.rb: devise_for :users, :controllers => { :sessions => “sessions” } You need to move the session views to this controller too. OR make a method in app/controllers/application_controller.rb: class ApplicationController < ActionController::Base layout :layout private … Read more