Skip to content

Instantly share code, notes, and snippets.

guard 'bundler' do
watch('Gemfile')
# Uncomment next line if Gemfile contain `gemspec' command
# watch(/^.+\.gemspec/)
end
guard 'rails' do
watch('Gemfile.lock')
watch(%r{^(config|lib)/.*})
end
@isaacbowen
isaacbowen / distant_counters.rb
Created September 29, 2011 19:06
Updates inverse counter caches when #collection_singular_ids= is called for an object extending ActiveRecord::Base
module DistantCounters
extend ActiveSupport::Concern
included do
reflect_on_all_associations.each do |reflection|
next unless reflection.macro == :has_many and reflection.is_a? ActiveRecord::Reflection::ThroughReflection
next unless reflection.klass.column_names.include? "#{name.underscore.pluralize}_count"
assoc_name = reflection.name.to_s.singularize
redefine_method "#{assoc_name}_ids=" do |ids|
@isaacbowen
isaacbowen / will_paginate.rb
Created August 30, 2011 21:37
extends will_paginate to play well with Twitter's Bootstrap
# config/initializers/will_paginate.rb
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= BootstrapLinkRenderer
super.try :html_safe
end
class BootstrapLinkRenderer < LinkRenderer