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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:10:01+00:00 2026-05-12T20:10:01+00:00

Say I have a form_for with a select menu to assign a User on

  • 0

Say I have a form_for with a select menu to assign a User on a belongs_to association:

...
form.select :user_id, @users, :prompt => "Select a User"
...

Currently I have @users in the controller as follows:

@users = User.all.map { |u| [u.full_name, u.id] }

I feel like this logic should maybe moved into a helper or even to the model.
But I am confused as to where to deal with this and how.

  • 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-05-12T20:10:02+00:00Added an answer on May 12, 2026 at 8:10 pm

    The general answer depends on how often you’re going to use it:

    • helper: used often but only in views or controllers
    • model: used often anywhere the model can be used (other models)
    • controller: used rarely and only for specific actions.

    However in your case, the answer is none of the above, and stop trying to reinvent the wheel. About 95% of the things people try to do with Rails are tasks that others have already done. There’s a very good chance that it’s either in the Rails Core or exist in either gem or plugin form.

    What you’re trying to do has already been done, and is built into the Rails core. It’s a ActionView::Helpers::FormOpitionsHelper method called collection_select

    collection_select does exactly what you want to do, it’s also much more robust than a single purpose method.

    It has the form of

    collection_select(object, method, collection, value_method,
      text_method, select_options = {}, html_options)
    

    value_method and text_method are sent to each item in collection to get the select value and the display text for each select option. It is not required that either are column names.

    Use it like this:

    <% form_for @whatever do |form| %>
      <%= form.collection_select :user_id, User.all, :id,
        :full_name, :prompt => "Select a User" %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 253k
  • Answers 253k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You just need to choose the right company. mail($number .… May 13, 2026 at 9:59 am
  • Editorial Team
    Editorial Team added an answer I don't understand what {ts '2009-12-08 00:00:00.000'} actually mean, since… May 13, 2026 at 9:59 am
  • Editorial Team
    Editorial Team added an answer "And would that also be, 'otherwise, update the fields in… May 13, 2026 at 9:59 am

Related Questions

I have a form that is dynamically generated, and has dynamically generated id's (and
I have an Access database. Let's pretend it's for a pet store. There's a
So lets say I have a dataset based on: SELECT TopicLink.*, Topic.Name AS FromTopicName,
I have a WPF form with a ListBox of items bound to a method

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.