Skip to content

Instantly share code, notes, and snippets.

@scttymn
scttymn / gist:1283177
Created October 13, 2011 02:18
Hack the counter_cache
# activerecord/lib/active_record/associations/builder/belongs_to.rb automagically creates
# the private methods for you if you include counter_cache in your belongs_to association.
# We simply override the basic behavior of these with our own conditions.
#
# For more information, check out:
# https://github.com/rails/rails/blob/733bfa63f5d8d3b963202b6d3e9f00b4db070b91/activerecord/lib/active_record/associations/builder/belongs_to.rb
# Lines 23 - 44
class Inventory < ActiveRecord::Base
belongs_to :user, counter_cache:true
@scttymn
scttymn / vim-cucumber.vim
Created August 17, 2011 03:39
Run a cuke in vim without ansi colors
"
" Vim Cucumber
"
" To install, put this in your .vim directory and source it.
" If you use Janus, place in your .vim/plugins directory and restart vim
function! Cuke()
let cmd = "cucumber --no-color %"
execute ":! " . cmd
endfunction