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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:28:03+00:00 2026-06-06T11:28:03+00:00

Hi I have a question about ruby on rails Apparently I have a statement

  • 0

Hi I have a question about ruby on rails

Apparently I have a statement like this:

def sort_column
    Product.column_names.include?(params[:sort]) ? params[:sort] : "name"
end

From what I read, it’s said that this method sort the column based on params[:sort] and if there no params the products will be sorted by “name”. However, I don’t understand the way this statement is written, especially the second “?”. Can someone explain it to me ?

  • 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-06T11:28:05+00:00Added an answer on June 6, 2026 at 11:28 am

    This is your code, rearranged for easier understanding.

    def sort_column
      cond = Product.column_names.include?(params[:sort]) 
      cond ? params[:sort] : "name"
      #  it's equivalent to this
      # if cond
      #   params[:sort]
      # else
      #   'name'
      # end
    end
    

    First question mark is part of a method name, the second one – part of ternary operator (which you should read about).

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

Sidebar

Related Questions

I have a question about models on Ruby on Rails: I have this method
I have a question about ruby on rails and the process of assigning variables
I am learning Ruby on Rails and I have a dumb question about the
This is a follow-up question to Uploading Pictures Ruby on Rails I have read
I'm reading a book about Ruby/Rails and have a question about something simple. In
I’m relatively new to Ruby, Sinatra, and DataMapper, but have a question about DataMapper
I'm a Ruby newbie. Have a very basic question about static and instance variables.
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have a general question about this. When you have a gallery, sometimes people

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.