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 6745317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:11:24+00:00 2026-05-26T12:11:24+00:00

edit 2 If you stumble across this, check both answers as I’d now use

  • 0

edit 2

If you stumble across this, check both answers as I’d now use pluck for this


I have a fairly large custom dataset that I’d like to return to be echoe’d out as json. One part is:

l=Location.find(row.id)
tmp[row.id]=l

but I’d like to do something like:

l=Location.find(row.id).select("name, website, city")
tmp[row.id]=l

but this doesn’t seem to be working. How would I get this to work?

thx

edit 1
alternatively, is there a way that I can pass an array of only the attributes I want included?

  • 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-26T12:11:25+00:00Added an answer on May 26, 2026 at 12:11 pm

    In Rails 2

    l = Location.find(:id => id, :select => "name, website, city", :limit => 1)
    

    …or…

    l = Location.find_by_sql(:conditions => ["SELECT name, website, city FROM locations WHERE id = ? LIMIT 1", id])
    

    This reference doc gives you the entire list of options you can use with .find, including how to limit by number, id, or any other arbitrary column/constraint.

    In Rails 3 w/ActiveRecord Query Interface

    l = Location.where(["id = ?", id]).select("name, website, city").first
    

    Ref: Active Record Query Interface

    You can also swap the order of these chained calls, doing .select(...).where(...).first – all these calls do is construct the SQL query and then send it off.

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

Sidebar

Related Questions

Just a little edit, in case it helps anyone out who happens to stumble
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
EDIT : It turned out that this can only be done through an external
I know this must be a fairly simple question, but I haven't managed to
I stumbled across this when doing a refactoring with Grails 2.0.1 but I pulled
I have just stumbled across the Backgroundworker object, and it seems like the tool
Scenario: I have a partial view that is used in several places across my
I stumbled upon this open source project Fake It Easy , and I have

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.