Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
geokit + will_paginate = can't sort by distance
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
thoraxe  
View profile  
 More options May 15 2008, 4:48 pm
From: thoraxe <erikmjac...@gmail.com>
Date: Thu, 15 May 2008 13:48:48 -0700 (PDT)
Local: Thurs, May 15 2008 4:48 pm
Subject: geokit + will_paginate = can't sort by distance
An excerpt from the geokit RDoc:

You can use includes along with your distance finders:

stores=Store.find :all, :origin=>home, :include=>[:reviews,:cities] :within=>5, :order=>'distance'

However, ActiveRecord drops the calculated distance column when you
use include. So, if you need to use the distance column, you‘ll have
to re-calculate it post-query in Ruby:
  stores.sort_by_distance_from(home)

In this case, you may want to just use the bounding box condition
alone in your SQL (there‘s no use calculating the distance twice):
  bounds=Bounds.from_point_and_radius(home,5)
  stores=Store.find :all, :include=>[:reviews,:cities] :bounds=>bounds
  stores.sort_by_distance_from(home)

This presents a problem because when you use @models = Model.paginate,
applying the sort to the results doesn't seem to do anything.

Does anyone know if there is a workaround to this?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mislav Marohnić  
View profile  
 More options May 15 2008, 8:04 pm
From: "Mislav Marohnić" <mislav.maroh...@gmail.com>
Date: Fri, 16 May 2008 02:04:23 +0200
Local: Thurs, May 15 2008 8:04 pm
Subject: Re: geokit + will_paginate = can't sort by distance

This is indeed a complicated problem.

If you want to paginate by distance, you'll have to calculate distance on DB
level; doing it in Ruby won't work. You could only do pagination in Ruby if
you fetched *all* the records, sorted them and then calling #paginate on an
array.

If you could update to Rails 2.1, I think your problem would be solved.
ActiveRecord 2.1 uses a preloading strategy for includes that I think would
take place here: 3 separate SQL queries would happen, one to load Stores and
other two to load Reviews and Cities.

Then maybe ActiveRecord won't drop the calculated column.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options May 15 2008, 8:33 pm
From: thoraxe <erikmjac...@gmail.com>
Date: Thu, 15 May 2008 17:33:22 -0700 (PDT)
Local: Thurs, May 15 2008 8:33 pm
Subject: Re: geokit + will_paginate = can't sort by distance
Mislav,

Yeah, I ended up having to do exactly as you stated:
      @contact = Barn.find(:all,
                            :conditions => conditions[:conditions],
                            :include => conditions[:associations],
                            :bounds => geo_params[:bounds])
      @contact.sort_by_distance_from(geo_params[:origin])
      @contacts = @contact.paginate(:page => params[:page], :per_page
=> 8)

This fetches all the records (~3000) and then paginates the array.

I'm using Rails 2.0.2 right now.  Is 2.1 still considered edge?  I
suppose I could give it a try, but this works OK enough for now.

On May 15, 8:04 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mislav Marohnić  
View profile  
 More options May 15 2008, 8:41 pm
From: "Mislav Marohnić" <mislav.maroh...@gmail.com>
Date: Fri, 16 May 2008 02:41:01 +0200
Local: Thurs, May 15 2008 8:41 pm
Subject: Re: geokit + will_paginate = can't sort by distance

2008/5/16 thoraxe <erikmjac...@gmail.com>:

> I'm using Rails 2.0.2 right now.  Is 2.1 still considered edge?

No, 2.1 has a release candidate:

  gem update rails --source http://gems.rubyonrails.org/

It has version number "2.0.991" because it isn't 2.1 final. I had no
problems upgrading, it's backwards-compat. It might break 3rd party code
like plugins that hack deep into ActiveRecord and ActionView---hope GeoKit
still works...

I suppose I could give it a try, but this works OK enough for now.

If fetching *3000* records *with* includes *into memory* for *each page* is
"OK" for you, then I don't think there is anything bad in the world by your
standards :)

Seriously - you don't want to paginate in Ruby. Try Rails 2.1; if that
breaks GeoKit then return here and we'll discuss some more.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options May 15 2008, 9:06 pm
From: thoraxe <erikmjac...@gmail.com>
Date: Thu, 15 May 2008 18:06:32 -0700 (PDT)
Local: Thurs, May 15 2008 9:06 pm
Subject: Re: geokit + will_paginate = can't sort by distance
The gem update didn't seem to have any abnormal effects.  It appears
though that Comcast is at it again, because Google is slow as the
hills, making it hard to test all my Google-based geo-functionality,
but it seems to be working.

So what are you suggesting that I do with the search now?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mislav Marohnić  
View profile  
 More options May 15 2008, 9:14 pm
From: "Mislav Marohnić" <mislav.maroh...@gmail.com>
Date: Fri, 16 May 2008 03:14:33 +0200
Local: Thurs, May 15 2008 9:14 pm
Subject: Re: geokit + will_paginate = can't sort by distance

First verify that your app is using the latest gem version (in
environment.rb).

On Fri, May 16, 2008 at 3:06 AM, thoraxe <erikmjac...@gmail.com> wrote:

> So what are you suggesting that I do with the search now?

With ActiveRecord 2.1 you might find that your initial query on this thread
works. I'm just guessing here, but it's worth trying out. Report back with
results.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options May 16 2008, 9:32 am
From: thoraxe <erikmjac...@gmail.com>
Date: Fri, 16 May 2008 06:32:35 -0700 (PDT)
Local: Fri, May 16 2008 9:32 am
Subject: Re: geokit + will_paginate = can't sort by distance
Looks like I need to update the other items as well...

/usr/lib/ruby/site_ruby/1.8/rubygems.rb:379:in
`report_activate_error': RubyGem version error: activesupport(2.0.2
not = 2.0.991) (Gem::LoadError)
        from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:311:in `activate'
        from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:337:in `activate'
        from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:336:in `each'
        from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:336:in `activate'
        from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:65:in
`active_gem_with_options'
        from /usr/lib/ruby/site_ruby/1.8/rubygems.rb:50:in `gem'
        from ./script/../config/boot.rb:29
        from script/server:2:in `require'
        from script/server:2


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options May 16 2008, 10:10 am
From: thoraxe <erikmjac...@gmail.com>
Date: Fri, 16 May 2008 07:10:08 -0700 (PDT)
Local: Fri, May 16 2008 10:10 am
Subject: Re: geokit + will_paginate = can't sort by distance
OK well, everythign is updated, but it unfortunately appears to be
ActiveScaffold that is the issue, not GeoKit :(

thoraxe@vmdora ~/railsapps/equine $ script/server -d
=> Booting WEBrick...
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.991/lib/active_support/
core_ext/module/aliasing.rb:31:in `alias_method': undefined method
`find_full_template_path' for class `ActionView::Base' (NameError)
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.991/lib/
active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain'
        from /home/thoraxe/railsapps/equine/vendor/plugins/
active_scaffold/lib/extensions/generic_view_paths.rb:26
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.991/lib/
active_support/dependencies.rb:508:in `require'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.991/lib/
active_support/dependencies.rb:353:in `new_constants_in'
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.991/lib/
active_support/dependencies.rb:508:in `require'
        from /home/thoraxe/railsapps/equine/vendor/plugins/
active_scaffold/environment.rb:63
         ... 31 levels...
        from /usr/lib/ruby/gems/1.8/gems/rails-2.0.991/lib/commands/
server.rb:39
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `require'
        from script/server:3


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options May 16 2008, 10:25 am
From: thoraxe <erikmjac...@gmail.com>
Date: Fri, 16 May 2008 07:25:19 -0700 (PDT)
Local: Fri, May 16 2008 10:25 am
Subject: Re: geokit + will_paginate = can't sort by distance
This is apparently a known issue with AS.  Somebody has posted a kind
of solution, I'm going to look into it.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options May 16 2008, 10:53 am
From: thoraxe <erikmjac...@gmail.com>
Date: Fri, 16 May 2008 07:53:09 -0700 (PDT)
Local: Fri, May 16 2008 10:53 am
Subject: Re: geokit + will_paginate = can't sort by distance
Either I did something wrong or it doesn't work.  But, until AS can
work with the latest rails, I guess I'm stuck doing something I
SERIOUSLY don't want to do :)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill  
View profile  
 More options Jun 4 2008, 10:28 pm
From: Bill <wrobb...@gmail.com>
Date: Wed, 4 Jun 2008 19:28:29 -0700 (PDT)
Local: Wed, Jun 4 2008 10:28 pm
Subject: Re: geokit + will_paginate = can't sort by distance
I'm having the *exact* same problem! I think that the thoraxe example
may be sped up by only fetching the needed db columns using :select

On May 16, 9:53 am, thoraxe <erikmjac...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
thoraxe  
View profile  
 More options Jul 22 2008, 9:15 pm
From: thoraxe <erikmjac...@gmail.com>
Date: Tue, 22 Jul 2008 18:15:40 -0700 (PDT)
Local: Tues, Jul 22 2008 9:15 pm
Subject: Re: geokit + will_paginate = can't sort by distance
Mislav,

I've recently updated both ActiveScaffold as well as Rails.  I'm also
likely running the latest will_paginate gem.  Everything is "working,"
except I have a horrendous memory leak issue with my ActiveScaffold
admin area.

If I can get that sorted soon, I'll be back in touch regarding this
particular issue.

Thanks for your help thus far.  I'm sure we can get it hammered out.

On Jun 4, 10:28 pm, Bill <wrobb...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »