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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:33:44+00:00 2026-06-11T01:33:44+00:00

I have a Rails app that pulls in music from Soundcloud. This data contains

  • 0

I have a Rails app that pulls in music from Soundcloud. This data contains a title, which I save as mix.sc_title but it’s not always properly formatted. I have added an additional attribute on my Mix model which I call mix.override_title

For display on my site, I want to use the override title if available, and the sc_title in all other cases.

I have a Mix model method to do this for me

def display_title
    override_title.blank? sc_title : override_title
end

Mixes#index grabs @mixes = Mix.where(:active => true) and mixes/index.html.erb looks like this:

<ul>
<% @mixes.each do |mix| %>
    <li><%= link_to mix.display_title, mix %></li>
<% end %>
</ul>

As you can see, I’m not directly using any mix attributes, and so I take a huge hit when I go to the DB, and I don’t actually benefit from it.

Is there a leaner way to get just the information I need? (mix.display_title)

I have tried Mix.select("display_title").where(:active => true) but it fails because display_title is not a real DB column

  • 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-06-11T01:33:46+00:00Added an answer on June 11, 2026 at 1:33 am

    You can do Mix.select("sc_title, override_title").where(:active => true) and it will work, since those are the actual fields that the method uses. I don’t really think getting the additional attributes gives you that much of a DB hit but sometimes selecting only what you need can be beneficial.

    As you start chaining on more Arel commands, consider putting the select into a model method:

    def select_active_titles
      select("sc_title, override_title").where(:active => true)
    end
    

    Edit: Your link_to helper also secretly calls mix.id to link to the right mix, so make sure it’s working and if not add id to the list of selected attributes.

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

Sidebar

Related Questions

I have a Rails app that needs to expose values from a database as
I have a small rails app on Heroku that pulls in my client's latest
I have a rails app that requires multi-table inheritance for which I am using
I have a Rails web app that shows data to user, however, that data
I have a hash being posted to my Rails app that looks like this:
I have a Rails 2.3.8 app with an action that pulls a large amount
I have a Rails app that is served by Apache and Passenger, using only
I have a Rails app that does everything I need it to do via
I have a rails app that is using Devise perfectly in development. I have
I have a rails app that has asynchronous processing, and I'm having trouble getting

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.