Skip to content

Instantly share code, notes, and snippets.

Avatar

James Bebbington jamesbebbington

View GitHub Profile
@jamesbebbington
jamesbebbington / application_controller.rb
Created Aug 4, 2011 — forked from robertsosinski/caching_with_request_forgery_protection.rb
Rack middleware and form tag patch to insert csrf tokens into cached pages
View application_controller.rb
class ApplicationController < ActionController::Base
TOKEN_PLACEHOLDER = "__CROSS_SITE_REQUEST_FORGERY_PROTECTION_TOKEN__"
after_filter :inject_csrf_token
private
def inject_csrf_token
if protect_against_forgery? && token = session['_csrf_token']
if body_with_token = response.body.gsub!(TOKEN_PLACEHOLDER, token)
View should_accept_nested_attributes_for.rb
class Test::Unit::TestCase
# Assert that the model accepts nested attributes for the given +associations+
#
# Example:
# should_accept_nested_attributes_for :orders
#
def self.should_accept_nested_attributes_for(*associations)
associations.each do |association|
should "accept nested attributes for #{association}" do