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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:39:26+00:00 2026-06-02T09:39:26+00:00

I have two models: countries and users country.rb class Country < ActiveRecord::Base has_many :users

  • 0

I have two models: countries and users

country.rb

class Country < ActiveRecord::Base
  has_many :users
end

user.rb

class User < ActiveRecord::Base
  belongs_to :country
end

All users (from all countries) shown on users/index.html.erb page.

users_controller.rb

  def index
    @users = User.all
  end

users/index.html.erb

<%= collection_select(:user, :country_id, Country.all, :id, :country_name) %>
<%= render @users %>

There is also select menu with all countries on users/index.html.erb.

How can I do the following: when someone select specific country there will be shown users only from selected country?

  • 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-02T09:39:29+00:00Added an answer on June 2, 2026 at 9:39 am

    This can only be achieved using javascript.

    The typical way to do it is with AJAX. Bind an onchange event to your select that requests a list of all users for the selected country. On the server you can then format that query as a set of select options, and insert then insert the response into the second drop down on the client.

    This looks like a good tutorial:
    http://www.falsepositives.com/index.php/2010/05/28/building-a-casscading-drop-down-selection-list-for-ruby-on-rails-with-jquery-ajax/

    Although you should try to find a more RESTful way of doing it.

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

Sidebar

Related Questions

I have two models Horse and Race. class Horse < ActiveRecord::Base has_many :races end
I have two models: class Member < ActiveRecord::Base has_many :member_tags end and class MemberTag
I have two models class User < ActiveRecord::Base has_many :posts searchable do text :post_titles
I have two models as follows: class Game << ActiveRecord::Base has_many :bells end class
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to
I have two models. order and line_item. class Order < ActiveRecord::Base has_many :line_items has_many
I have two models: class Sentence < ActiveRecord::Base attr_accessible :sentence_id, :authority_name #... end class
I have two Models called User and Membership. User has_many :memberships Membership belongs_to :user
I have two models Company and Role related by has_many and belongs_to association respectively.
I have two models related as follows. USERS has_many :celebrations has_many :boards, :through =>

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.