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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:59:37+00:00 2026-06-14T02:59:37+00:00

I have just read the Rails API definition for option_from_collection_for_select. Returns a string of

  • 0

I have just read the Rails API definition for option_from_collection_for_select.

 Returns a string of option tags that have been compiled by iterating over the collection   and assigning the result of a call to the value_method as the option value and the text_method as the option text

Now I am very new to rails so was wondering if someone could break this down into smaller chunks and explain what is happening, dumb it down if you will, the explanation is very high level (well for me at the moment)

Thank you

  • 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-14T02:59:39+00:00Added an answer on June 14, 2026 at 2:59 am

    Using the example from the Ruby on Rails API, let’s assume you have a Person model that has an id attribute and a name attribute.

    Say you have a form that creates a new project and assigns it to a person. Maybe you want to have a drop down select for what person you’re assigning this project to. You could use options_from_collection_for_select for something like this.

    <%= f.label :person, "Assigned Person" %>
    <%= f.select(:person, options_from_collection_for_select(@people, "id", "name") )
    

    (f by the way would be referring to the @project variable for our example form here.)

    What this would do is create an option in your select drop-down for each person contained in the instance variable @people. Each of the <option> tags would have the id of that person assigned to its value attribute, and the text for that option would be the person‘s name.

    So if your @people variable contained [#<Person id: 1, name: "Brock Sampson">, #<Person id: 2, name: "Byron Orpheus">], you would get HTML output like this:

    <label for="project_person">Assigned person"</label>
    <select id="project_person" name="project[person]">
      <option value="1">Brock Sampson</option>
      <option value="2">Byron Orpheus</option>
    </select>
    

    Does that make more sense?

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

Sidebar

Related Questions

Just have read sass changelog and found out that FSSM (the gem that had
I am new to Java. I just read that class variables in Java have
In my Rails 3.1.1 project I have an ActiveModel that talks to API (ripped
I have recently been advised that for my current rails app relationships I should
Just starting to learn Ruby on Rails. I'm using RoR 3. I have read
I have just started considering using the HTML 5 api for a Rails/JQuery project,
I have a Rails app that has been running fine for months. The other
I have just read this in the book OpenCV 2 Computer Vision Application Programming
i have just started using Moq ver (3.1) and i have read blogs and
I have just switched from svn to mercurial and have read some tutorials about

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.