OK, forgive the awful code -- still not comfortable writing Ruby as i'm
mostly a JavaScript guy. I can get a result with...
1. puts GroupSet.all().collect {|item|
2. route = Child.filter(:group_set_id => item.id).collect {|o|
3. [o.lat, o.lng]
4. }
5.
6. {:id => item.id, :route => route}
7. }.to_json()
For context see my pastebin here: http://pastebin.com/j7Qnk1dv
Is this a reasonable approach? Feel my knowledge is lacking :/
On Saturday, 14 September 2013 17:21:51 UTC+1, Adam Gamble wrote:
>
> I have a PhotoSet, which has a one_to_many relationship with Photos. Each
> Photo has a latitude (lat) and longitude (lng) associated with it, along
> with (DateTime) date_taken.
>
> Using Sinatra as a REST service, my desired output would be:
>
> [{
> title: set1,
> photos: [[lat1, lng1],[lat2, lng2]] # or even better, photos renamed to
> 'route'
> }]
>
> ...with each [lat, lng] ordered by date_taken...
>
> Totally lost as to how to achieve this, I can get this far using Sequel's
> JSON Serializer plugin:
>
>
> PhotoSet.where(:parent_id => nil)
>
>
> .to_json(:include => {
>
>
> :photos => {
>
>
> :only => [:lat, :lng],
>
>
> },
>
>
> })
>
> which returns:
>
> [
> {
> "id": 1,
> "title": "",
> "date_created": "2013-09-14T15:53:16+00:00",
> "photos": [
> {
> "lat": 52.95386867000556,
> "lng": -2.2866811700101857
> }
> ]
> }
> ]
>
> Thanks,
>
> Adam
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.