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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:17:00+00:00 2026-05-26T21:17:00+00:00

So I have had various forms of this working in the last while, but

  • 0

So I have had various forms of this working in the last while, but never all working together.

for reference I have categories / Brands / Products, with the right relationships working: the site is http://emeraldcityguitars.com to see it in action.

So in my brands controller show action:

    @category = Category.find_by_url_name(params[:category_id])
    @brand = Brand.find(params[:id])
    @search = Product.brand_id_equals(@brand.id).category_id_equals(@category.id).descend_by_price
    @products = @search.paginate(:page => params[:page])    

this works fine, as is evidenced in my log:

  Category Load (25.6ms)   SELECT * FROM "categories" 
  Category Load (0.2ms)   SELECT * FROM "categories" WHERE ("categories"."url_name" = 'acoustic-guitars') LIMIT 1
  Brand Load (0.6ms)   SELECT * FROM "brands" WHERE ("brands"."id" = 14) 
  Product Load (4.8ms)   SELECT * FROM "products" WHERE ((products.category_id = 3) AND (products.brand_id = 14)) ORDER BY products.price DESC LIMIT 6 OFFSET 0
  SQL (0.2ms)   SELECT count(*) AS count_all FROM "products" WHERE ((products.category_id = 3) AND (products.brand_id = 14)) 
   Rendering template within layouts/application
   Rendering brands/show

You can see that its grabbing products descending by price.

In my Brand#show I am doing the following:

 <%- form_for [@category, @brand], :html => {:method => 'get', :id => 'sort_form', :class => 'sort_form'} do -%>
          <label>Sort by: </label> <%= select_tag :order, product_sort_options %>
          <%= submit_tag 'Go' %>
        <%- end -%>

The goal being that a user could sort by a couple different options.

I also have this in my products_helper:

def product_sort_options
    options_for_select([
      ['', nil],
      ['Newest to Oldest', 'descend_by_date'],
      ['Oldest to Newest', 'ascend_by_date'],
      ['Price: Highest to Lowest', 'descend_by_price'],
      ['Price: Lowest to Highest', 'ascend_by_price'],
      ['Name', 'ascend_by_name']
    ])
  end

The issue I am having is that if I click the drop down and do price lowest to highest it reloads the page, with “?order=ascend_by_price” at the end of the url but there is no change in the order of the products.

any help is appreciated.

  • 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-26T21:17:01+00:00Added an answer on May 26, 2026 at 9:17 pm

    You’ll need to add in a call to include the value of your :order parameter. It only gets included in the search by default if you’re doing something like Product.search(params[:search]) (and the order parameter would then have to be in params[:search][:order]).

    So, something like this should work:

    @search = Product.brand_id_equals(@brand.id)
    @search.category_id_equals(@category.id)
    @search.order(params[:order] || :descend_by_price)
    

    I’ve split it out to make it easier to read. The last line specifies to order by the value of your order parameter or the default ordering if that’s not available.

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

Sidebar

Related Questions

I have had a look all over, but it doesn't seem as though my
I have had this problem crop up a few times and I can't figure
I have had several situations when i would like to do that. This could
I have had Delphi 2007 for a while. I tried the Delphi 2009 trial.
I have had a few problems getting this right, so I wanted to ask
I have seen this same question in many forms on this site and in
I really had no idea what to title this question. Assume I have a
This has been plaguing me for a while. I have a page in my
I've had this problem for a while, and no one I've talked to on
I have searched high and low and tried various patterns but it seems I

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.