Ruby on Rails
Monday, March 30, 2015
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:
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, sequel-rails 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!
-- 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:
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, sequel-rails 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!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bc7a118a-ac9f-4aac-9f8a-7de7de61a1f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment