我在workorder控制器中有以下索引:
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' ")
感谢您的帮助!
答案 0 :(得分: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