Skip to content

Instantly share code, notes, and snippets.

@metalelf0
metalelf0 / habtm_scope.rb
Created January 28, 2011 13:39
How to define a named scope in a habtm relation
# First model: tag.rb
# note that pomodori is a custom plural for pomodoro
class Tag < ActiveRecord::Base
has_and_belongs_to_many :pomodori
end
# Second model: pomodoro.rb
# here is how to define a Rails 3 scope through the join table: