你在这里把事情搞混了。
1)您可以在单个 ActiveRecord 对象上使用(实例)方法。
# Returns an ARRAY with all programschedule instances
all_ps = ProgramSchedule.all
# You can now iterate over over the array
all_ps.each do |ps|
# in here you can call the instance method on the actual model instance
ps.instance_method
end
# Definition of this method in app/models/program_schedule.rb
class ProgramSchedule < ActiveRecord::Base
def instance_method
# Foo
end
end
2)您可以在 ActiveRecord 模型本身上运行一些类方法。
ProgramSchedule.class_method
# Definition of this method in app/models/program_schedule.rb
class ProgramSchedule < ActiveRecord::Base
def self.class_method
# Bar
end
end