Skip to content

Instantly share code, notes, and snippets.

@cmattson
cmattson / gist:5847954
Last active December 18, 2015 21:29
Need to get params back from some OAuth provider that doesn't let you explicitly pass them back? Though it's not (well?) documented, OmniAuth will store any existing params in request.env["omniauth.params"].
# In your CallbacksController, pass omniauth.params:
@user = User.find_for_PROVIDER_oauth(
request.env["omniauth.auth"],
request.env["omniauth.params"],
current_user
)
# In your model, add a second parameter to the method definition:
def self.find_for_PROVIDER_oauth(auth, params=nil, signed_in_resource=nil)
@cmattson
cmattson / stupid_devise_tricks.md
Last active August 2, 2021 21:15
Stupid Devise Tricks

Stupid Devise Tricks

Devise can be a daunting beast even if you've used it frequently. For new users, it can be especially baffling as the documentation often assumes a familiarity with its inner workings. To help bridge the gap, here are some frequent scenarios and possible solutions.

###Oh my God, it's complaining about unknown methods! What?!

This most commonly occurs because you have enabled features in your Devise model (e.g. user.rb) but didn't create the associated fields with a migration.

Devise's tendrils are manifold; each feature has an associated symbol in your model's devise block, field(s) in your database, and configuration options in your Devise initializer.

@cmattson
cmattson / gist:5852139
Created June 24, 2013 18:06
Reduced case of inconsistent list behavior

If you start an ordered list immediately following text:

  1. Like this
  2. The editor will provide list item 2
  3. And also every subsequent item
  4. But it won't render as a list when processed

If you insert an extra line break:

  1. And start a list
  2. Then everything works as expected
@cmattson
cmattson / cloud_files_form_post.rb
Last active December 19, 2015 08:19
Ruby version of Rackspace's example form signing code. Full details on Cloud Files FormPost capability are in the API docs: http://docs.rackspace.com/files/api/v1/cf-devguide/content/FormPost-d1a555.html sprintf is used here because it breaks across multiple lines nicely; there's nothing stopping you from using inline interpolation (heck, or con…
require 'openssl'
path = '/v1/account/container/object_prefix'
redirect = 'https://myserver.com/some-page'
max_file_size = 104857600
max_file_count = 10
expires = (Time.now.to_i + 600)
key = 'mykey'
hmac_body = sprintf("%s\n%s\n%s\n%s\n%s", path, redirect, max_file_size, max_file_count, expires)
signature = OpenSSL::HMAC.hexdigest('sha1', key, hmac_body)
@cmattson
cmattson / factory_girl_demo.rb
Created August 1, 2013 06:38
Tasty pies made in a factory.
# Here we have a default peach pie
FactoryGirl.build(:pie)
# ...or an apple pie
FactoryGirl.build(:pie, :apple)