Custom authentication strategy for devise

I found this very helpful snippet in this thread on the devise google group initializers/some_initializer.rb: Warden::Strategies.add(:custom_strategy_name) do def valid? # code here to check whether to try and authenticate using this strategy; return true/false end def authenticate! # code here for doing authentication; # if successful, call success!(resource) # where resource is the whatever you’ve … Read more

Monkey Patching in Rails 3

The initializer directory is a good place to collect all those little scraps. Since I tend to go a bit overboard with core extensions, I like to make a folder there called “extensions” and toss them all in there. So, try /config/initializers/string_extension.rb, or /config/initializers/extensions/string.rb, or something similar. Either way, you can just forget about them … Read more

How do you configure WEBrick to use SSL in Rails?

While the scripts directory in Rails 4 is gone, the bin directory remains. You can get WEBrick working with an SSL certificate by editing the bin/rails script. Tested on Rails 4 and Ruby 2.1.1, installed with rbenv. Much of this is from this blog post and this Stack Overflow question. #!/usr/bin/env ruby require ‘rails/commands/server’ require … Read more

Adding cookie session store back to Rails API app

If you’re on Rails 5, and want to preserve config.api_only = true you could extend the middleware to add the sessions layer, adding this code after class Application < Rails::Application in config/application.rb config.middleware.use ActionDispatch::Cookies config.middleware.use ActionDispatch::Session::CookieStore, key: ‘_namespace_key’ This could come in handy when you want to have a rails api-only enabled app but have … Read more

OpenSSL::SSL::SSLError on Heroku [duplicate]

After some searching here is what I found: If you’re using Ruby to open connections to an external server over https, eg. the Facebook Graph API, you may run into the following error: OpenSSL::SSL::SSLError:SSL_connectreturned=1errno=0state=SSLv3readservercertificateB:certificateverifyfailed This error is due to Ruby not being able to find the certification authority certificates (CA Certs) used to verify the … Read more