9
我想動態生成示波器。比方說,我有以下型號:在導軌模型中動態生成示波器
class Product < ActiveRecord::Base
POSSIBLE_SIZES = [:small, :medium, :large]
scope :small, where(size: :small)
scope :medium, where(size: :medium)
scope :large, where(size: :large)
end
我們可以更換的scope
調用的東西基礎上,不斷POSSIBLE_SIZES?我認爲我違反DRY重複他們。
非常整潔,非常感謝! (而且,我知道有關論據的範圍,我認爲這在我的具體情況中更清晰) – spike