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 6614357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:19:45+00:00 2026-05-25T20:19:45+00:00

My webapp needs to encrypt its session data. What I setup is: config/initializers/encryptor.rb: require

  • 0

My webapp needs to encrypt its session data. What I setup is:

config/initializers/encryptor.rb:

require 'openssl'
require 'myapp/encryptor'

MyApp::Encryptor.config[ :random_key ] = OpenSSL::Random.random_bytes( 128 )
Session.delete_all

app/models/session.rb:

require 'attr_encrypted'

class Session < ActiveRecord::Base
  attr_accessible :session_id, :data
  attr_encryptor :data, :key => proc { MyApp::Encryptor.config[ :random_key ] }, :marshal => true

  # Rest of model stuff
end

That all works great, and keeps the session data secured. Here’s the problem: when I run my custom rake tasks it loads the initializer and clears all the sessions. Not good!

What can I put in my initializer to make sure it ONLY runs for the webapp initialization? Or, what can I put in my initializer to make it NOT run for rake tasks?

Update: OK, what I’ve done for the moment is add MYAPP_IN_RAKE = true unless defined? MYAPP_IN_RAKE to my .rake file. And then in my initializer I do:

unless defined?( MYAPP_IN_RAKE ) && MYAPP_IN_RAKE
    # Web only initialization
end

Seems to work. But I’m open to other suggestions.

  • 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-25T20:19:46+00:00Added an answer on May 25, 2026 at 8:19 pm

    You might make a modification to your application in `config/application.rb’ like this:

    module MyApp
      def self.rake?
        !!@rake
      end
    
      def self.rake=(value)
        @rake = !!value
      end
    

    Then in your Rakefile you’d add this:

    MyApp.rake = true
    

    It’s nice to use methods rather than constants since sometimes you’d prefer to change or redefine them later. Plus, they don’t pollute the root namespace.

    Here’s a sample config/initializers/rake_environment_test.rb script:

    if (MyApp.rake?)
      puts "In rake"
    else
      puts "Not in rake"
    end
    

    The programmable nature of the Rakefile affords you significant flexibility.

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

Sidebar

Related Questions

I've got a webapp running on CherryPy that needs to access the CherryPy config
My webapp needs to auto-login when the user access the app url: example: http://myapp/home.xhtml?token={3bcdc006-05fc-4ce1-953a-17375edcf2a2}
Part of my latest webapp needs to write to file a fair amount as
I have a java webapp which needs to upload files via http and then
My WebApp needs to authenticate user before allowing any sort of access. The scenario
I'm developing an application using ASP.Net. For first the idea: My WebApp needs an
I'm using Python in a webapp (CGI for testing, FastCGI for production) that needs
My webapp sometimes needs to store a dump (~20MB file). My webapp is running
I've got this webapp that needs some memory tuning. While I'm already profiling the
I'm building a WebApp that needs to send a text and a filename through

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.