Hello Railers,
I’m building an API backend using Rails 4 and I’m struggling with
finding a
more elaborate way to do model queries straight from the URL than a mere
?name=Bob&age=43. What I’m after is some way to make AND, OR, LIKE etc
operations straight from the URL query parameter.
Loopback on node.js has something similar
http://docs.strongloop.com/display/public/LB/Where+filter#Wherefilter-and/or
:
With Loopback you can define your query as a javascript object {filter:
{where: {and: [{name: {like: ‘Bob%’}}, {age: 43}]}}, which, translated
to
query parameters, would be:
?filter[where][and][0][name][like]=Bob%25&filter[where][and][1][age]=43.
I’ve been looking at using Arel, Squeel
https://github.com/activerecord-hackery/squeel, sequel-rails
<goog_33395714> and of course normal ActiveRecord but none of them seem
to
provide this kind of URL-to-ORM query mapping out of the box. Does
anyone
have any other pointers or ideas of how to make this happen?
Thanks!