Skip to content

Instantly share code, notes, and snippets.

Created August 4, 2014 19:32
What would you like to do?
Imagine I have tickets that belong to events. As a developer, I only want to access tickets that belong to an event, and I want to safeguard against accessing all tickets (contrived example, but anyway). If event ids start at 0, and I set the default scope to an event_id of -1, then if I forget to set an event (which would select all tickets), I…
class Ticket < ActiveRecord::Base
belongs_to :event
default_scope where(event_id: -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment