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

  • Home
  • SEARCH
  • 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 7059701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:15:51+00:00 2026-05-28T04:15:51+00:00

I would like my website to allow users to select a product category such

  • 0

I would like my website to allow users to select a product category such as ‘books’ and return the results that are in that category. The code I’m using is from Railscast #228 Sortable Table Columns.

How do I change the code to look for a specific string in the category column?

Controller:

class ProductsController < ApplicationController
 helper_method :sort_column, :sort_direction

 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
end

Helper function:

def sortable(column, title = nil)
 title ||= column.titleize
 css_class = column == sort_column ? "current #{sort_direction}" : nil
 direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
 link_to title, {:sort => column, :direction => direction}, {:class => css_class}
end

HTML:

<tr>
<th><%= sortable "name" %></th>
<th><%= sortable "price" %></th>
<th><%= sortable "released_at", "Released" %></th>
</tr>
  • 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-28T04:15:51+00:00Added an answer on May 28, 2026 at 4:15 am

    Figured it out, it was actually pretty easy, created a new function and instead of using strings (which was not working) I used id #s and then plugged in ‘sort_category’ into my Solr function for search.

    def sort_category
    params[:category] ? params[:category] : 1..12
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a website that allow users to bring/integrate their wordpress
On our website we would like to allow users to share content that they
I would like to track users clicks on my website. For that purpose, I
I would like to allow users to log in into my website with OpenID.
Websites like Wordpress and Tumblr allow designers to create themes that users can select.
I would like to publish a website using msbuild. Since I have a website
i would like to display images on my website that are stored on a
I would like to allow my users to see other users data. I am
I have a photo album gallery within my website and would like to allow
I am working on a website and would like for my users to be

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.