On 6 mai, 12:34, "Sergio Cambra .:: entreCables S.L. ::."
<[email protected]> wrote:
> On Miércoles, 5 de Mayo de 2010 14:27:27 gs84 escribió:
>
>
>
> > I have the following associations with 3 classes: Commune,
> > Entiteservice, Offreservice
> > class Commune < ActiveRecord::Base
> > end
>
> > Commune has 2 attributes: lattitude, longitude
>
> > ['acos(cos(:lattitude)*cos(entiteservices.commune.lattitue)*cos(entiteservi
> >ces.commune.longitude-:longitude)
> > +sin(:lattitude)*sin(entiteservices.commune.lattitude))*:r < :max',
> > {:lattitude => commune_usager_lat, :longitude =>
> > commune_usager_long,:r => 6378.138, :max => 10}]
> >     end
> > end
>
> > But i am  always getting an mysql error "Unknown column
> > 'entiteservices.commune.lattitue' "   :
>
> The field is lattitude, not lattitue, and the table is communes,
> entiteservices.commune.lattitude is wrong, change all entiteservices.commune
> with communes, and lattitue with lattitude. You only have to set conditions as
> you would do in where clause of a sql query. Anyway, it's cleaner to use
> geokit plugin than put so much code in your controller
>
Hi Sergio,
I have in the commune model:
  acts_as_mappable :default_units => :kms,
                   :default_formula => :sphere,
                   :distance_field_name => :distance,
                   :lat_column_name => :lattitude,
                   :lng_column_name => :longitude

So i am  trying to conditions_for_collection with Geokit plugin like
the following:

def conditions_for_collection
      if session[:usager_id] != nil
        commune_usager = Usager.find(session[:usager_id]).commune
#city of the current usager
        commune_usager_lat = commune_usager.lattitude  #lattitude of
current usager's city
        commune_usager_long = commune_usager.longitude #longitude of
current usager's city

        [
        Commune.find(:all, :origin => [commune_usager_lat,
commune_usager_long], :include =>
[:offreservices, :entiteservices], :conditions => "distance <
10", :order => 'distance asc')
        ]

     end
end

But i am getting the following error: " undefined method `%' for
#<Array:0x931e2c4> "

Can you or someone tell me how i can use the Geokit plugin in the
conditions_for_collection method

Thans in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to