Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个模型(用户) has_many :bookings
预订有一个完整的字段
我希望能够查看预订完成的用户的所有预订我还希望有时能够显示用户的所有预订,无论是否完成
在我的模型中设置它的最佳方法是什么?
假设complete是一个布尔值Bookings:
complete
Bookings
class User < ActiveRecord::Base has_many :bookings end class Bookings < ActiveRecord::Base belongs_to :user scope :completed, where(complete: true) end @user.bookings.completed #Complete bookings @user.bookings #All bookings