Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:54:19+00:00 2026-05-23T08:54:19+00:00

I am trying to add a before_destroy filter to Devise’s SessionsController. Here is what

  • 0

I am trying to add a before_destroy filter to Devise’s SessionsController.

Here is what I have attempted:

I created a module containing the before_destroy filter and another module with the method that I wanted it to call.

module UserTracker

  prepend_before_filter :stop_tracking, :only => [:destroy]

  module TrackerStopper
    def stop_tracking
      # Do stuff
    end
  end

  include TrackerStopper
end

And then I tried to extend the SessionsController with the UserTracker module.

Devise::SessionsController.extend UserTracker

This was not working, because devise was not loaded when my module was loaded. This resulted in the error below:

uninitialized constant Devise::SessionsController (NameError)

Basically, I would like to run a method each time a session gets destroyed, without overwriting the entire SessionsController, but I can’t figure out a way to mix it in.

Thanks!

UPDATE 1: I gave up on building a separate gem, here is the code I have attempted in my application.

UserTrackersController.rb

class  UserTrackersController < Devise::SessionsController
  prepend_before_filter :stop_tracking, :only => [:destroy]

  def stop_tracking
    current_user.update_attributes(:current_sign_in_ip => nil)
  end
end

routes.rb

#--
# Devise
devise_for :users, :controllers => { :sessions => 'user_trackers'}

The problem now is that if I try to log in (or log out in this case), I get the following error:

Template is missing

Missing template user_trackers/new with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/net/user10/ardavis2/rubydev/spacecamp/app/views", "/net/user10/ardavis2/.rvm/gems/ruby-1.9.2-p180@spacecamp/gems/devise-1.3.4/app/views"

I don’t want my new UserTrackersController to do anything except add some small code to the existing Sessions controller. So I still need devise to function as it did before.

Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:54:19+00:00Added an answer on May 23, 2026 at 8:54 am

    Why don’t you really extend SessionsController?

    E.g.

    class MySessionsController < Devise::SessionsController
      # my changes
    end
    

    And in the routing config, you can tell devise_for which SessionsController to use:

    devise_for :controllers => { :sessions => "my_sessions" } 
    

    Edit: you can generate devise views by invoking:

    rails g devise:views <scope>
    

    This will generate app/views/devise/sessions/new.html.erb which is the only view you need for this to work. Just copy it to app/views/my_sessions/new.html.erb and it will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a method in my code behind at runtime add
I'm trying to add another function to a large program I've been working on.
I'm trying to add some basic file-download functionality to my Rails application and have
I am trying to add a module to my Rails 3.1 app, I've been
i'm trying to add some animated gif into static image (canvas), here's my start
I'm trying to add a space before every capital letter, except the first one.
I'm trying add a tab to my web page that looks like this: Using
Trying to add an onclick handler to my tabs, and can't seem to get
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
Trying to add a 'box' to a form at design time, I looked up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.