Skip to content

Instantly share code, notes, and snippets.

@JohnAmican
Created April 29, 2012 18:02
Show Gist options
  • Save JohnAmican/2552289 to your computer and use it in GitHub Desktop.
Save JohnAmican/2552289 to your computer and use it in GitHub Desktop.
class Classroom < ActiveRecord::Base
belongs_to :school
attr_accessible :code, :name, :school_id
validates :code, :name, :school_id, :presence => true
def school_name
school.name
end
class << self
['code', 'name'].each do |type|
define_method("#{type.pluralize}_by_school_id") do |school_id|
Classroom.where(school_id: school_id).order(type).map(&(type.to_sym))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment