How would I clear all rails sessions? How would I clear all rails sessions? ruby-on-rails ruby-on-rails

How would I clear all rails sessions?


Whether it's DB or cookie store, use rake tmp:sessions:clear


If you are storing your sessions in a db then

rake db:sessions:clear


In Rails 4, the accepted answer (rake db:sessions:clear) no longer works because ActiveRecord::SessionStore was extracted into the active_record-session_store gem. (See here for further explanation)

You can now either install the active_record-session_store gem and use rake db:sessions:clear as in Rails 3, or create a custom Rake task that looks like so:

namespace :db do    namespace :sessions do        desc "Clear ActiveRecord sessions"        task :clear => :environment do            sql = 'TRUNCATE sessions;'            ActiveRecord::Base.connection.execute(sql)        end    endend