1

ワークオーダーコントローラーに次のインデックスがあります。

def index
   @workorders = Workorder.scoped
   @workorders = Workorder.where("created_at > #{params[:after]}") if params[:after].present?
end

ANDになるように次を追加するにはどうすればよいですか。maxsync <> 'E' の場合にのみワークオーダーを含めたい。パラメータ :after が存在するかどうかに関係なく。

私はこれを試しました:

@workorders = Workorder.scoped.where("maxsynch != 'E' ")

助けてくれてありがとう!

4

1 に答える 1

1

次のようにスコープを連鎖できます。

def index
   @workorders = Workorder.scoped.where("maxsynch != 'E' ")
   @workorders = @workorders.where("created_at > ?", params[:after]) if params[:after].present?
   #examples:
   @workorders = @workorders.where(parent_id: params[:parent_id]) if params[:parent_id].present?
   @workorders = @workorders.active if params[:filter_active].present?
end
于 2013-10-02T18:28:08.587 に答える