0

I am developing a Rails application using ActiveScaffold.

The thing is that I need to filter a list of results by a date range.

(SQL equivalent 'BETWEEN ? AND ?')

I know that ActiveScaffold has a feature that already does that, but it has too many options. (Past, Future, Range, =, ...., Between). In this case, I only need the Between option in that combo.

I tried overriding the field using the Helper, but the closest I got was to display 3 different combos (one for year, one for month, one for day).

Is there any way to override Active Scaffold so that only displays the "Between" option?

EDIT Active Scaffold already does the search part well. I am trying to change the visual part so it doesn't display so many options.

EDIT 2 The calendar plugins for rails are dated from 2009 or they aren't under maintenance.

Wiggin
  • 329
  • 1
  • 3
  • 17

1 Answers1

1

You can use a range as a parameter in AR.

Model.where(:date => from..to)

Also, I'm not sure if ActiveScaffold has something to do with it. Normally, all the tasks like this one can be perfectly solved within plain ActiveRecord.

EDIT: As it turns out, author also needs to get the user's input for the boundaries. This is a common task that can be solved with one of the thouhands js plugins for datepickers. I would recommend you not to stick to ActiveScaffold for that purpose. Try this simple Jquery datepicker, and it will turn normal text field into that drop-down calendar. You will only need several lines of javascript then. If you need further advise, just ask.

roman-roman
  • 2,746
  • 19
  • 27
  • Thanks for your answer. Unfortunately my problem is a visual problem. ActiveScaffold actually does the filtering well, but how it displays it is my problem. Ideally I would need to display two datepickers. – Wiggin May 13 '14 at 14:17
  • Ok, then we face two dedicated tasks here: one for actually _selecting_ the records, and another one for getting user input. My answer addresses the first one only. I'll update the answer now. – roman-roman May 13 '14 at 14:21
  • Thank you for pointing me in the jQuery datepicker, it was just what I needed for the text fields. Marking your answer as the correct. – Wiggin May 13 '14 at 18:38