Tuesday, August 31, 2010

NoMethodError: undefined method 'coordinates' for #

In trying to use the latest Sunspot code (from github) for geo search with Rails 3.0.0 , I was getting the following error while running Sunspot.index!(Location.all), where Location is my ActiveRecord class for storing locations:

After searching through the new code I found that coordinates is no longer a valid field type, but instead location is to be used. location expects an object that responds to lat and lng. Sunspot provides a handly little struct called Coordinates to be this object. So, here is my model code for setting up the search:

notice the virtual attribute called coordinates which wraps the lat & lng ActiveRecord attributes. My search code now looks like this:

And my search results are coming in as expected.

1 comment:

  1. The firm develops, produces, markets, and licenses fully built-in Live Casino solutions to gaming operators. In Live Casino, a sport presenter (i.e., dealer) runs the game from a on line casino gaming desk that is followed in real-time by way of a video stream. End users (i.e., the players) make betting decisions on their devices 카지노사이트 (computers, smartphones, tablets, etc.).