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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:15:16+00:00 2026-06-05T07:15:16+00:00

In a Rails app I’m setting up nested routes resource Country do resource State

  • 0

In a Rails app I’m setting up nested routes

resource Country do
  resource State
  resource City
  resource User
  resource Post
end

I now want to display users that have posted within a country at ../country/1/users

In the User controller I have:

def index 
  @user = User.includes(:posts, :city, :state, :country)
  @user = @users.where("states.country_id = ?", params[:country_id]) if params[:country_id]
  @active_users = @users.where('posts_count > ?', 0).ranked_scope
end

I’m, getting:

PG::Error: ERROR:  column reference "posts_count" is ambiguous
LINE 1: ...untry_id" WHERE (states.country_id = '1') AND (posts_co...

I’m not sure if this is because:

  1. There is a posts_count column on User, City, State, Country models and the query does not know which on to use. If so, what is the correct syntax to specify the table?
  2. I’m stringing together two where clauses incorrectly.
  3. Something else….?

I’d appreciate any suggestions or ideas.

  • 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-05T07:15:16+00:00Added an answer on June 5, 2026 at 7:15 am

    OK, I eventually got to the bottom of this. The following query was incorrect

    @users = @users.where("states.country_id = ?", params[:country_id]) if params[:country_id]
    

    Post belongs to User, and Post has one Country through State. Without a direct relationship in one direction between USer and Country, I modified the query to

    @users = @users.where(id: Country.find(params[:country_id]).users.uniq if params[:country_id]
    

    (and double checked all my model relationships were properly configured).

    Works!

    The error message was not very helpful in tracking this down though!

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

Sidebar

Related Questions

My rails app has a user model that has a HABTM relationship with interests
I have a Rails app with impressionist and friendly id, I want to show
I'm deploying a Rails app on Heroku (for now) via git, and would also
in my Rails app have this routes.rb: devise_for :admin namespace :admin do root :to
Our Rails app is using Restful Authentication for user/session management and it seems that
My Rails app uses the jquery.post() method to send some data from a clickable
I am developing a rails app and have a question. In my routes.rb: map.connect
Im developing a Rails app that will contain a web front end as well
In my ruby-on-rails app, I have nested comments that can be nested an arbitrary
In my rails app, I want to render certain pages within a lightbox but

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.