我有两个模型:国家和用户
国家.rb
class Country < ActiveRecord::Base
has_many :users
end
用户.rb
class User < ActiveRecord::Base
belongs_to :country
end
users/index.html.erb 页面上显示的所有用户(来自所有国家/地区)。
users_controller.rb
def index
@users = User.all
end
用户/index.html.erb
<%= collection_select(:user, :country_id, Country.all, :id, :country_name) %>
<%= render @users %>
users/index.html.erb 上还有所有国家的选择菜单。
我该如何执行以下操作:当有人选择特定国家/地区时,只会显示来自所选国家/地区的用户?