Skip to content

Instantly share code, notes, and snippets.


James Bebbington jamesbebbington

View GitHub Profile
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
after_filter :inject_csrf_token
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