Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4609

Do something after succesful login in Rails devise

$
0
0

I have a Rails app and use devise for registration and sign-up of users. Now I want to store the date of the last successful login on the user.

Basically I thought about overwriting the create method in the session controller but if the password would be wrongly entered it would the store the wrong timestamp. Is there some way of telling rails to call a specific action or block after succesful login? Is there an after_action I can simply add?

class Users::SessionsController < Devise::SessionsController  skip_before_action :verify_authenticity_token, only: :create  def new    login = I18n.t('header.menu.not_logged_in.login')    @title = login    @meta_description = login    @noindex = true    super  end  def create    super  end  protected  def after_sign_in_path_for(resource_or_scope)    set_location_path(resource_or_scope) || stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)  end  private  def set_location_path resource    if resource&.fitaf_employee?      admin_root_path    elsif resource&.non_fitaf_employee?      if current_user.accounting_company.present?        home_company_path(company_id: current_user.accounting_company.id, id: current_user.accounting_company.id)      else        home_companies_path      end    end  endend

Do I have to put the code in after_sign_in_path_for in the sessions_controller above? Is there no model I can amend/add?


Viewing all articles
Browse latest Browse all 4609

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>