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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:04:08+00:00 2026-05-31T05:04:08+00:00

In my controller I have: if params[:sort].nil? @sort = created_at else @sort = params[:sort]

  • 0

In my controller I have:

if params[:sort].nil?
  @sort = "created_at"
else
  @sort = params[:sort]
end
@konkurrencer = Konkurrencer.where("id NOT IN(?)", @clicked).order("#{@sort} DESC")

I like to add if params[:sort] is different from "created_at", "ratings", or "rating" then it should sort after "created_at".

  • 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-31T05:04:09+00:00Added an answer on May 31, 2026 at 5:04 am

    First, .order("#{@sort} DESC") isn’t a good idea when @sort is taken straight from params. It would be better to use .order('? DESC', @sort).

    http://guides.rubyonrails.org/security.html#sql-injection

    I’m not sure if I read your question correctly but I’m assuming you want created_at to be the default order with the other valid options being ratings and rating.

    @order = case params[:sort]
    when 'ratings'
      'ratings DESC'
    when 'rating'
      'rating DESC'
    else # anything else
      'created_at DESC'
    end
    
    @konkurrencer = Konkurrencer.where("id NOT IN(?)", @clicked).order(@order)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my controller I have: @taletids = Taletid.where(:online => true) @taletids.each{|taletid| taletid.calculate_total(params[:search])} @taletids.sort! In
In my controller: Article.author_ids_in(params[:filters][:author_ids]) This of course returns an error (You have a nil
I have a controller action which I would like to call another controller action.
In my controller i have an action which does not have a corresponding view.
I have the following controller code: def calculate_quote @mouldings = Moulding.find( params[:id].split(,), :select =>
I have this terribly large controller in my app. I'd really like to make
Most of the actions in my controller have statically-defined parameter lists and so they
I have controller with action new , and I want it to create ActiveRecord::Base
Several of my controller actions have a standard set of failure-handling behavior. In general,
In my controller I have model operations that can return empty results. I've setup

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.