Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3313294
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:05:55+00:00 2026-05-17T22:05:55+00:00

When I just the to_json method it seems to ignore all other options… any

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:05:55+00:00Added an answer on May 17, 2026 at 10:05 pm

    I’m not sure how to_json behaves on collections that haven’t fully been enumerated yet. It’s probably a bug that it ignores your applied scopes, but this might work better:

    @location_for_map.limit(5).all.to_json(:only => [:name, :lat, :lng])
    

    @location_for_map.limit(5) doesn’t actually return an array; it returns an object that represents all the scopes applied so far, and only actually fetches the array of results when you start treating that object like an array.

    Applying the all method forces Rails to fetch the results immediately, and to_json probably knows better how to work with the actually array than the placeholder object. (All my guess, but give it a go, regardless.) Might be worth seeing if there’s a bug report yet, and, if not, filing one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just to make this clear, I have looked at the other questions on this
Did jquery ajax $.post() method work in Safari 3.2.3 (525.29) or other? I am
It seems this is a common question/problem but despite checking out a number of
I'm just getting started with REST and I've been reading this post and the
This seems like a pretty efficient way to do error handling, but I want
I have a form that seems to never validate. The form is just three
I've just added the jQuery UI combobox to a page. It seems it restricts
I know this seems like I should have immediately found the one example out
I'm working on MVC3 UserManagement and on local (VS2010) all seems to be working
This question seems simple at first glance, but has slowed down my work! Please,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.