Trying to create a scope in rails 3 for has habtm relationship
问题 I'm trying to do a basic search on an active record but am having trouble because of the has_and_belongs_to_many relationship. Below are the records and scopes I've created. Class Section << ActiveRecord::Base has_and_belongs_to_many :teachers attr_accessible :department, :class_size scope :department_scope, lambda { |dept| where("department = ?", dept) } scope :teacher_fname_scope, lambda { |n| joins(:teachers) & Teacher.has_first_name(n) } end Class Teacher << ActiveRecord::Base has_and