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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:09:38+00:00 2026-06-05T00:09:38+00:00

I have these in my controller: class AccountsController < ApplicationController def index @search =

  • 0

I have these in my controller:

class AccountsController < ApplicationController
 def index
  @search = Account.search(params[:search])
  @accounts = @search.order("id desc").includes(:chef).page(params[:pagina]).per(10)
 end
end

My view:

<%= f.text_field :username_or_email_or_chef_name_contains %>

Works fine! But, when I search based on email, I got this error:

ActiveRecord::StatementInvalid in Accounts#index 
Mysql2::Error: Column 'id' in order clause is ambiguous: SELECT  `accounts`.`id` AS t0_r0, `accounts`.`chef_id` AS t0_r1,...

If I take off the .includes(:chef) of account controller, works fine.

QUESTION

Why this error? For performance reasons, I wouldn’t like to remove the include from account controller.

  • 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-05T00:09:39+00:00Added an answer on June 5, 2026 at 12:09 am

    The accounts table and chefs table each have an id column, so MySQL doesn’t know which of those columns it should order by. Try specifying the table name in the order by clause:

    @accounts = @search.order("accounts.id desc").includes(:chef).page(params[:pagina]).per(10)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi there I have 3 files in rails as follows: 1)Located at app/controller/listings_controller.rb class
I have a view controller with 6 buttons on it. Each of these buttons
Using Rails 3.1.3. I have Accounts and Users. One Account can have many Users.
I have an UITabBar controller managing several controllers (using SDK 3.0). One of these
I'm trying to create a generic Controller Class for generic events. But these these
I have a 'account roles' controller (for my AccountRole model) in my application using
I have made a base controller class that overrides OnActionExecuting as follows: public class
I have two action methods in my controller class both with same name. One
Lets say I have a controller class like this. public class InStorePickupController : Controller
I have a root view controller which has few buttons. On click of these

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.