Search code examples
ruby-on-railscontrollers

Rails controller contents into separate configuration file


Does anybody know a good way to separate out a controller item into a separate file? I have the following in of my controller.

def admin?
    session[:password] == "password"
end

But I'd like to separate the "password" into a separate file so I can ignore it from a public git repo?

Is there an easy way to do this? Without storing this in a database?


Solution

  • you can try to use ENV variables. first set the environment variable to a value.

    export MYAPPPASSWORD=1234

    then use this in an initializer

    # config/initializers/my_app_password.rb
    ENV['MYAPPPASSWORD'] = `printf "%s" $MYAPPPASSWORD`
    

    then you can just call ENV['MYAPPPASSWORD']