views:

18

answers:

1

When I just the to_json method it seems to ignore all other options... any ideas how to fix this?

var places = <%=raw @location_for_map.limit(5).to_json(:only => [:name, :lat, :lng]) %>;

I'm trying to plug in points from json on a google map, but noticed the points never got smaller with any of my scopes. where, order, limit...

I could put a limit(5) and it would still return 1000 records regardless.

The controller looks something like this:

sort = case params[:sort]
       when "name" then session[:sort] = "name"
       when "min_price" then session[:sort] = "min"
       when "avg_price" then session[:sort] = "cache_price"
       when "rating" then session[:sort] = "cache_rating DESC NULLS LAST"
       end

@locations = Location.find(params[:id])       
@base = @locations.places.active

#@location_for_map = @locations.places.limit(5)

unless params[:tags].blank?
  @base = @base.tagged_with(params[:tags])
end

unless params[:price_high].blank?
  price_high = (params[:price_high].to_f * Currency.rate(params[:currency]))
  price_low = (params[:price_low].to_f * Currency.rate(params[:currency]))
  @base = @base.where("cache_price BETWEEN ? AND ?",price_low,price_high)
end

@base = @base.order(session[:sort])

#@location = @locations.places.active.paginate :page => params[:page]
@location = @base.paginate :page => params[:page]
@location_for_map = @base