質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top