Skip to content

Instantly share code, notes, and snippets.

@KieranP
KieranP / 1 app-models-session.rb
Last active October 8, 2020 16:11
A Ruby on Rails implementation of a Database and Cookie hybrid session storage for Devise that supports session revocation and storage of session ip and user agent for security (similar to Github)
# A user session class, a simplified mix of the following code samples:
# * https://github.com/blog/1661-modeling-your-app-s-user-session
# * http://www.jonathanleighton.com/articles/2013/revocable-sessions-with-devise/
class Session < ActiveRecord::Base
# Uncomment if you use Hobo Fields, else add these yourself
# fields do
# session_id :string, :index => true, :unique => true
# accessed_at :datetime
# user_ip :string
@bf4
bf4 / rails32_http_patch_support.rb
Last active June 4, 2018 09:04
HTTP PATCH support in Rails 3.2
# Rails 3.2 support for HTTP PATCH.
fail "Remove this patch" if Rails::VERSION::MAJOR > 3
# see http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates/
# https://github.com/rails/rails/pull/505
# Be very conservative not to monkey-patch any methods until
# the relevant files are loaded.
ActiveSupport.on_load(:action_controller) do
ActionDispatch::Request.instance_eval do
# Is this a PATCH request?
@xaviershay
xaviershay / http_client_spec.rb
Created December 13, 2011 02:19
Running a rack app in a thread for integration tests.
require 'integration_helper'
require 'rack'
require 'rack/handler/webrick'
describe HttpClient do
before :all do
@server = WEBrick::HTTPServer.new(
:Port => 9293,
:Logger => Rails.logger,
:AccessLog => Rails.logger