我想在我的两个查询中排除 where 子句,如下所示:
where_clause = where("(created_at >= ? and created_at < ?) or (updated_at >= ? and updated_at < ?)", range_start_date, range_end_date, range_start_date, range_end_date)
@book_instances = BookInstance.limit(pagination.items_per_page).
offset((pagination.page - 1) * pagination.items_per_page).
where_clause.
order(:id)
@pagination.total_items = BookInstance.where_clause.count
但 ActiveRecord 并不高兴。我认为您可以独立分解查询位。