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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:50:10+00:00 2026-06-09T23:50:10+00:00

I am building an app where users can post. Each post an be upvoted

  • 0

I am building an app where users can post. Each post an be upvoted and downvoted. Where the posts are displayed, I have a little form that allows the user to filter the posts. It simply passes a paramter to url called params[:post_filter] (localhost:3000/somepage?post_filter=value). Now, this works just fine and dandy, except the private method I wrote to modify the query does not work.

Here is my query:

def room
            @posts = Post.where('lesson_id = ?', params[:id]).order(post_filter_params).page(params[:page]).per(30)
    end

and here is my private method:

private

def post_filter_params
    chosen_option = params[:post_filter].to_i == 1 or 2 or 3 ? params[:post_filter] : '1'
    case chosen_option
    when 1
        'created_at DESC'
    when 2
        'upvotes DESC'
    when 3
        'downvotes DESC'
    end
end

Now, whenever I replace the .order() value with one of the strings in my private method, everything works as planned. However, placing private method name inside the .order() value does not work. Any ideas for what is going on?

EDIT

To make sure all values are the same data type I did this but it still does not work:

def post_filter_params
    param_option = params[:post_filter].to_i
    chosen_option = param_option == 1 or 2 or 3 ? param_option : 1
    case chosen_option
    when 1
        'created_at DESC'
    when 2
        '(upvotes - downvotes) DESC'
    when 3
        'downvotes DESC'
    end
end
  • 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-09T23:50:12+00:00Added an answer on June 9, 2026 at 11:50 pm

    I don’t think that private method does what you think it does.

    How about this?

    def post_filter_params
      case params[:post_filter].to_i
      when 1
        'created_at DESC'
      when 2
        'upvotes DESC'
      when 3
        'downvotes DESC'
      else
        'created_at DESC'
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an app that allows users to post. Those posts can be
I'm building an app where each user can have multiple profiles. Users can upload
I am building a rails app where users can post, must like a form.
I'm building an app that allows users to view pictures off a website. I
I'm building an app that allows users to snap pictures using the iPhone camera,
I'm building a web app where users can build custom web pages that pull
Im building an app which uses Sqlite DB. Users can enter their information into
I am building a little app for users to create collections. I want to
I'm building a fairly simple Android app (sdk revision 14: ICS) which allows users
I'm building an app in CodeIgniter. I have an invoice form which uses jQuery

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.