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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:52:51+00:00 2026-06-19T00:52:51+00:00

I am new to Ruby and Rails. I made a simple application where the

  • 0

I am new to Ruby and Rails.

I made a simple application where the index page diaplays a Cars table with columns for make, model, and type (sportscar, SUV, luxury).

I have made it so I can click a column header and sort by that column

I also added a form above the table with a checkbox for each car type where the user can check/uncheck the boxes and click ‘submit’ and the table will only show cars with the types that were checked.

What I want to be able to do is sort by some column, and then check some boxes/click submit and show the result with the list still sorted AND also filtered.

Right now, I can either sort or filter, but if I do one action my application forgets about the previous action.

What is the RESTful way to do this?

Should I keep the ‘settings’ in the session hash, and construct a URI from that every time the user makes a new HTTP request?

  • 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-19T00:52:53+00:00Added an answer on June 19, 2026 at 12:52 am

    What’s wrong with including sort/filter parameters in the request URI? For example, when you submit the filter form for make of “honda”, the uri will be something like /cars?filter[make]=honda. If you also include sort options, the uri could be /cars?filter[make]=honda&sort_by=make.

    Inside your controller, you could access these through the params hash:

    class CarsController < ApplicationController
      def index
        @filter = params[:filter]  || {}
        @order  = params[:sort_by] || "created_at"
    
        @cars = Car.where(@filter).order(@order)
      end
    end
    

    You can generate these uri’s by including the parameters in path helpers in your views:

    link_to "Only show hondas", cars_path(:sort_by => @order, :filter => {:make => "honda"})
    link_to "Sort by year",     cars_path(:sort_by => :year,  :filter => @filter)
    

    This way, @filter and @order will be “persisted” between requests unless you explicitly change them. (These links are not DRY… you should generate them dynamically).

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

Sidebar

Related Questions

I'm new to Ruby on Rails and I'm trying to model my table relationships.
I'm new to ruby/rails and trying to build a simple Projects / Tags app
I am new to Ruby on Rails and I am trying to make a
i am new to Ruby on Rails. I am trying to make a one
I have just started with ruby on rails, have made a new rails project
I am fairly new to Ruby and Rails, made a few blogs etc. I
I'm fairly new to Ruby on Rails. I've made a blog, and loaded a
First I'm quite new to ruby and rails... I have a little application working
I've successfully made a new application with the rails new command from a clone
I'm new in Ruby/Rails, so, my question: what is the perfect way to upload

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.