geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

Rails3 syntax #19

Closed craibuc closed 3 years ago

craibuc commented 14 years ago

I'm trying to migrate to Rails3 syntax. The following query works:

@users = User.find(
  :all,
  :joins => "INNER JOIN profiles AS profiles ON users.id=profiles.user_id",
  :conditions => ["users.disabled = ? AND users.hidden = ?", false, false],
  :include => :profile,
  :origin => ll,
  :units => :miles, 
  :order => order_by
  ).paginate(:per_page => @per_page, :page => params[:page])

If I convert this query to Rails3 syntax using scopes, the query resembles: @users = User.valid.joins(:profile).includes(:profile).order(order_by).paginate(:per_page => @per_page, :page => params[:page])

Question: how do I reference the :units and :origin in this syntax? I've tried a variation of the Rails3 syntax to use scopes and the .find method:

@users = User.valid.joins(:profile).includes(:profile).find(
  :all,
  :origin => ll,
  :units => :miles, 
  :order => order_by
  ).paginate(:per_page => @per_page, :page => params[:page])

but I get an error that reads "Unknown key(s): origin, units".

Is the plugin Rails3 compatible?

andre commented 14 years ago

The plugin hasn't been updated for Rails3. Frankly I'm surprised you got the query to work (with the old syntax) on Rails3.

I've noodled around a little bit with the Rails3 chainable scopes for the plugin, but nothing to show for it.

craibuc commented 14 years ago

Lucky, I'd guess.

I would offer my help, but I'm too new to Rails to be of much value.

Any ideas on when your plugin will be update for R3?

Thanks for the work you've done so far, BTW.

andre commented 14 years ago

Any ideas on when your plugin will be update for R3?

I'm not personally going to be able to tackle it anytime soon. Would love to see something in the community take it on.

craibuc commented 14 years ago

do you have any ideas on what needs to change? how much work is involved? something a novice could tackle?

triemstr commented 13 years ago

Has anyone tried this one for Rails 3?

https://github.com/jlecour/geokit-rails

https://rubygems.org/gems/geokit-rails3

It will be a bit before I can upgrade to Rails 3 but would love to hear if anyone out in the wild is finding jlecour's version works.

craibuc commented 13 years ago

This works for me in Rails 3 and the 'geokit-rails3' gem:

@users = User.valid.joins(:profile).includes(:profile). geo_scope(:origin => ll, :within => distance). order(order_by). paginate(:per_page => @per_page, :page => params[:page])

triemstr commented 13 years ago

Cool, I'm totally going to try it too then in a few weeks when I can move my app to Rails 3. Thanks for checking it out and hope it continues to work for you.

ryankopf commented 3 years ago

Closing this as there have been significant updates since.