Rails – How to override devise SessionsController to perform specific tasks when user signs in?

Alternatively, you can create your own sessions controller class SessionsController < Devise::SessionsController def new super end def create self.resource = warden.authenticate!(auth_options) set_flash_message(:notice, :signed_in) if is_navigational_format? sign_in(resource_name, resource) if !session[:return_to].blank? redirect_to session[:return_to] session[:return_to] = nil else respond_with resource, :location => after_sign_in_path_for(resource) end end end And in routes.rb add: devise_for :users, controllers: {sessions: “sessions”}

How do I enable :confirmable in Devise?

to “enable” confirmable, you just need to add it to your model, e.g.: class User # … devise :confirmable , …. # … end after that, you’ll have to create and run a migration which adds the required columns to your model: # rails g migration add_confirmable_to_devise class AddConfirmableToDevise < ActiveRecord::Migration def self.up add_column :users, … Read more

“undefined method `env’ for nil:NilClass” in ‘setup_controller_for_warden’ error when testing Devise using Rspec

In Rails 5 you must include Devise::Test::IntegrationHelpers instead Devise::Test::ControllerHelpers: # rails_helper.rb config.include Devise::Test::IntegrationHelpers, type: :feature See more: https://github.com/plataformatec/devise/issues/3913#issuecomment https://github.com/plataformatec/devise/pull/4071

Extending Devise SessionsController to authenticate using JSON

This is what finally worked. class Api::V1::SessionsController < Devise::SessionsController def create respond_to do |format| format.html { super } format.json { warden.authenticate!(:scope => resource_name, :recall => “#{controller_path}#new”) render :status => 200, :json => { :error => “Success” } } end end def destroy super end end Also change routes.rb, remember the order is important. devise_for :users, … Read more

Creating a `Users` show page using Devise

You should generate a users_controller which inherits from application_controller and define there your custom show method. Don’t forget to create a view and routes for it. Ex: #users_controller.rb def show @user = User.find(params[:id]) end #in your view <%= @user.name %> #routes.rb match ‘users/:id’ => ‘users#show’, via: :get # or get ‘users/:id’ => ‘users#show’ # or … Read more

Ruby/Rails: How do you customize the mailer templates of Devise?

I think you’ll need to manage the Devise views yourself. Try the following in a console: rails generate devise:views This will generate all the views Devise uses (including mailer templates), which you can now customize. The mailers you’re looking for should then be in ‘app/views/devise/mailer’ If you want to generate scoped views, or only a … Read more