I need to implement some search functionality within a Rails application. Most of the stuff I have found is generally aimed at simple plain-text search. I am trying to implement something much more specific. The sort of functionality I am looking to create is this (from a C application):
The form just submits the data entered by the user. So I need to translate strings like “3..7” into SQL conditions for the where method e.g.
TestLine.where( "test_int >= ? and test_int <= ?", MinInt, MaxInt )
It seems like this is something that already exists somewhere. The exact format expected is not too important, as the users are not shared between the Rails and C applications. How would this be done?
FWIW the specific functionality you describe is actually supported directly. Well.. almost. From the docs:
Of course then it’s a matter of translating the user’s string input to a Range, which isn’t very complex, e.g.:
It would probably make the most sense in a
scopeon your model. (Of course a shortcut would be to simplyeval '9..12'butevaling input from the end user is a really, really bad idea.)