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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:51:02+00:00 2026-06-05T08:51:02+00:00

I have been checking a lot of posts here in Stack Overflow, Rails documentation

  • 0

I have been checking a lot of posts here in Stack Overflow, Rails documentation from http://api.rubyonrails.org/ and other places. I am absolutely confused as to how many parameters I should pass. I have seen 4 and 5. This is what I want to do.

I have a form that has a country name that I want to change to a drop down list using another table with a list of countries.

The current code on my form is:

<%= f.text_field :country %>

Country is on another table User. Instead of having people type in the country I want them to select the country from table Country listing name instead of id from the table, then use name from table Country to update country on table User.

I am still learning the current database terminology. I am used to using database, tables within a database, records/row within a table, field.column on a record, etc.

How would I code the collection_select statement to produce the list of country names from another table?

I have spent hours almost all day long trying to figure this out. Somehow I was able to figure out how to use seeds.rb to load my Country table.

I am using Rails 3.2.3 and Ruby 1.9.3. I am using a PostgreSQL database.

Any help would be 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-06-05T08:51:04+00:00Added an answer on June 5, 2026 at 8:51 am

    Depending if the proper relationships to the other table has been set “such as belongs_to or has_many” you could do something like this.

    <%= collection_select(:some_other_active_record, :country, Country.all, :id, :name)  %>
    

    Should render out as

    <select name="some_active_record[country_id]">
       <option value="1">USA</option>
       <option value="2">Canada</option>
       <option value="3">Mexico</option>
       [...]
    </select>
    

    You should read this page http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/collection_select

    The first argument is the instance of the class (“Active Record / table”) to be used for the select tag your form is for.

    The second is a method call to get the attribute of object corresponding to the select tag such as how country belongs_to your main active record ie “country_id / contry_ids”

    The third argument is an array of objects representing the tags. Basicly all your contries ie.. “Country.all”

    The fourth is the name of a method which, when called on a member of collection, returns an array of child objects representing the tags. Basically the id of the the country instance found with Country.all which is be put in the html value=”some country id”

    The next argument is how you display the name of the country.

    The next after that is a set of options which I’m not going to go over.

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

Sidebar

Related Questions

I have been checking around the PayPal API and got this, a webView displaying
I have been checking out some of the possible timers lately, and System.Threading.Timer and
I have been solving a lot of memory leaks but have been unsuccessful in
I have been checking out some info about 64-bit driver development; I found that
We have been going back and forth a lot around our office lately about
In my line of work, we have to do a lot of duplicate checking
I have a reputation system on my site, similar to Stack Overflow, where a
I have been checking google analytics. they track user exit very efficiently. I had
I have been able to find a lot of information on actual logic development
Have been working on this question for a couple hours and have come close

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.