Ruby on Rails Wednesday, July 25, 2012

Sure, glad it helped, it's not a trivial problem you've just taken care of! :)

I mean that's the process basically (until you deploy to prod at least): fix thing A, then fix things B and C that depended on previous A's implementation and so on. Try to get into RSpec so that a solved problem stays that way.

2012/7/25 Erwin <yves_dufour@mac.com>
OK, and thanks a lot
using Kaminari.paginate_array(@geo_items)  solved my issue ...
I can get an array of items in which I can insert the distance from
the search point and sort the array on this distance..
I could not save this info into the item instance as it depends upon
each user's search ...

thanks a lot again !!

On 25 juil, 16:18, Gintautas Šimkus <dihita...@gmail.com> wrote:
> As far as your clarification goes, well it depends on whether or not you
> can sort with SQL. If you cannot, then you are left with sorting results
> with your custom Ruby code.
>
> BTW Kaminari can paginate an arbitrary array, so you might work with that
> (by defining a sorting method or something more/less complicated).
>
> 2012/7/25 Gintautas Šimkus <dihita...@gmail.com>
>
>
>
>
>
>
>
>
>
> > It will not be sorted. You just pass an array basically to that named
> > scope. And you will get results that satisfy the array so to speak, but it
> > can come in any order. Just add .order('id DESC')  (or ASC) clause
> > explicitly.
>
> > 2012/7/25 Erwin <yves_duf...@mac.com>
>
> >> Thanks Colin for your answer
>
> >> let me draw the big picture :
> >> in my iatme controller ,before the display ( scope and pagination) , I
> >> searched for geolocalized data of item ( with distance from the
> >> search), and I get a sorted array of Item Ids, (already sorted on the
> >> distance :  item_ids = [ 5, 2, 1, 10, ...] )
>
> >> then I display the items using Kaminari pagination  ( Kaminary doesn't
> >> paginate an array )
>
> >> @items = Item.geo_filtered_with(geo_ids).page params[:page]
>
> >> and my model scope is :
>
> >>   scope :geo_filtered_with, lambda { |item_ids|
> >>     where(:id => item_ids)
> >>   }
>
> >> so I wonder if the result of the scope will keep the same order as the
> >> item_ids
> >> which means :
> >> items.id IN [ 5, 2, 1, 10, ...]  will always get items records  5, 2,
> >> 1, 10 .... in this order
>
> >> that's why I did not specified a sort order with the scope, is it
> >> clear ?
>
> >> On 25 juil, 14:38, Colin Law <clan...@googlemail.com> wrote:
> >> > On 25 July 2012 13:35, Erwin <yves_duf...@mac.com> wrote:
>
> >> > >  I am using this scope , in which geo_ids is a sorted array of
> >> > > Ids ...
>
> >> > >  scope :geo_filtered_with, lambda { |geo_ids|
> >> > >     where(:id => geo_ids)
> >> > >   }
>
> >> > > is the resulting output always sorted according to this order ? or
> >> > > should I modify it ?
>
> >> > Since you have not specified any sort specification the order is not
> >> > defined.  If you want a particular order you must specify it.
>
> >> > Colin
>
> >> > > thanks for your feedback
>
> >> > > --
> >> > > You received this message because you are subscribed to the Google
> >> Groups "Ruby on Rails: Talk" group.
> >> > > To post to this group, send email to
> >> rubyonrails-talk@googlegroups.com.
> >> > > To unsubscribe from this group, send email to
> >> rubyonrails-talk+unsubscribe@googlegroups.com.
> >> > > For more options, visithttps://groups.google.com/groups/opt_out.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Ruby on Rails: Talk" group.
> >> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> rubyonrails-talk+unsubscribe@googlegroups.com.
> >> For more options, visithttps://groups.google.com/groups/opt_out.
>
> > --
> > Pagarbiai,
> > Gintautas
>
> --
> Pagarbiai,
> Gintautas

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Pagarbiai,
Gintautas

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment