你好,我有一个模范学生,有一个实地考试录取_end:日期我想定义一个范围,以帮助我让所有入学的学生在特定的一天结束时尝试这个,但我的问题是如何让它显示我的观点
这是我定义的范围
attr_accessible :address, :address, :admission_ends, :certificate, :country, :date_of_birth, :diploma_id, :email, :first_name, :full_name, :gender, :how_did_you_hear_about_us, :lg_area, :middle_name, :other, :relationship_with_applicant, :state_of_origin, :surname, :telephone_number, :telephone_number, :title, :title, :image, :amount_deposit, :balance, :full_payment, :next_payment, :part_payment, :programme, :mode_of_payment
belongs_to :admin
mount_uploader :image, ImageUploader
belongs_to :diploma
belongs_to :payment
scope :admission_due, -> { where("students.admission_ends >= ?", Date.today) }
答案 0 :(得分:0)
使用lambda或proc定义范围,因为Rails 4不允许使用范围这样的范围。
你可以像这样通过结束日
scope :admission_due, lambda { |end_date| where("admission_ends >= ?", end_date) }
在视图中
Student.admission_due(Date.today)