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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:08:23+00:00 2026-05-23T19:08:23+00:00

If I do this: User.where(….).order(#{params[:order]} #{params[:dir]}) If no, then for arguements sake say I

  • 0

If I do this:

User.where(....).order("#{params[:order]} #{params[:dir]}")

If no, then for arguements sake say I want to be paranoid and ensure the values for the symbols :order and :dir are within a range, how could I do that?

Say I create an array of allowable safe values:

safe_order = %[:updated_at :created_at]

what would be the ruby way of ensuring params[:order] is either nil or contains 1 of the values in the safe_order array?

  • 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-23T19:08:23+00:00Added an answer on May 23, 2026 at 7:08 pm

    Take a look at http://railscasts.com/episodes/228-sortable-table-columns

    Specifically some small methods to check the parameters or return defaults:

     def index
       @products = Product.order(sort_column + " " + sort_direction)
     end
    
     # ...
    
     private
    
     def sort_column
       Product.column_names.include?(params[:sort]) ? params[:sort] : "name"
     end
    
     def sort_direction
       %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to do something like this: user.items << Item.new(params[:item] , :computer => Computer.new(params[:computer]
I have a user control let say UC1 . This user control have viewmodel
We have a column with values like this (USER.F1, USER.F2. USER.F3 ...) for regular
I want to do something like this: {{user.name.toLowerCase()}} but I get this error: Error:
I am doing this: user = User.find( params[:id] ) when I do: user.section_id it
I have developed user control for ActiveX control in C# then register this component
I want to do something like this: user clicks on a button Choose color,
When an user remove my app from Facebook interface, I want to delete this
I have one user control in wpf. And I want to use this user
THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO sql and

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.