RailsCasts Pro episodes are now free!

Learn more or hide this

Daniel Martin's Profile

GitHub User: etdsoft

Comments by Daniel Martin

Avatar

I think this is till a great solution, but I'd like to suggest you consider using the following in ./config/application.rb instead of a separate initializer:

ruby
# Load application ENV vars and merge with existing ENV vars. Loaded here so can use values in initializers.
ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}

Source:

http://quickleft.com/blog/simple-rails-app-configuration-settings

Avatar

Use BCrypt::Password.create() instead of BCrypt::Engine and the library takes care of the salt for you:

ruby
def create(secret, options = { :cost => BCrypt::Engine::DEFAULT_COST })
  Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(options[:cost]), options[:cost]))
end

http://bcrypt-ruby.rubyforge.org/classes/BCrypt/Password.html#M000007