# scope ``` /model scope: cheap, -> { where("price > 50")} scope: adult, -> { where("age > 18")} ``` ``` /controller Product.cheap //找出價格低於50的商品 //等於Product.where("price > 50") ``` ``` Product.cheap.adult //找出價格低於50的成人商品 //可以串多個scope ``` * scope的效果類似於類別方法 `default_scope { order(id: :desc) }` * default_scope會強制所有經由此model的查詢都執行order(id: :desc) * 要關閉必須用`unscope(要取消的)`,如`comment.unscope(:order).order(新的排序)`