No commit activity in last 3 years
No release in over 3 years
Chain a date range to any named_scope on any date field with specified white listed fields
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Introduction

Rangetastic allows you to filter results of a named_scope call on any dates using any of a list of whitelisted fields you specify.

Configuration & Usage

To acheive this you need to install rangetastic, but first install gemcutter and enable it for gems if you haven't already:

sudo gem install gemcutter

gem tumble

sudo gem install rangetastic

Then inside your environment.rb

config.gem "rangetastic"

Then in your model pass in the fields you wish to allow to be searchable using the between filter

class Order < ActiveRecord::Base
  acts_as_rangetastic :fields => ["ordered_on", "fulfilled_on"]
end

You can then chain the between scope with any named_scope call you make:

Order.fulfilled.between(1.week.ago, 10.minutes.ago, "fulfilled_on")

But if you (or someone nasty!) try to use a field that is not whitelisted, it will raise ActiveRecord::StatementInvalid

Now you can also access this with the following syntax for any field ending with _on that is on the Model you are calling from like so.

Order.fulfilled.ordered_between(1.week.ago, 10.minutes.ago)

In this new version of rangetastic you can also query on _at fields. If you have an _at field such as created_at you can now

Order.fulfilled.created_between(1.week.ago, 10.minutes.ago)

However if you have an _on field and _at field the on field will take precedence over the at. If you want to access the _at field over _on field you will need to use the .between and whitelisted fields method specified first.

But if your field isn't on the Model or isn't an _on or an _at field then it will raise the standard NoMethodError.

Thanks to spraints for some inspiration.