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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:07:22+00:00 2026-06-14T18:07:22+00:00

Possible Duplicate: I want to return a single result using .find() with Ruby on

  • 0

Possible Duplicate:
I want to return a single result using .find() with Ruby on Rails

This is my code

<%= f.select :user_id, User.find(:user_id).collect {|t|
    [t.user_name, t.id]} %>

which gives the output

Couldn't find User with id=user_id

It doesn’t seem to pass the variable instead it’s passing ‘user_id’ as a string.

I just want it to return a single result into either a select list or label

I’m fairly new to ROR, I might be going about this the completely wrong way. Any help is much 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-14T18:07:23+00:00Added an answer on June 14, 2026 at 6:07 pm

    You are passing :user_id to the find method, which is a symbol, not a user id.

    You have to pass a number to find, then find will search for the record with that id.

    Another problem, why are you calling collect on the result of find ? Find return only one row, not an array.

    Here is how you should structure your code :

    You should get the user variable into the controller, for instance :

    @user = User.find(params[:id])

    Beware, find throws an exception if the model is not found, as you saw, consider using find_by_id that returns nil if no model is found.

    Then, you can use @user in your view.

    If you want to display a select tag with only the user in it, do the following :

    <%= f.select, :user_id, options_for_select([[@user.user_name, @user.id]]) %>

    Check http://guides.rubyonrails.org/form_helpers.html for form helpers.

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

Sidebar

Related Questions

Possible Duplicate: trailing return type using decltype with a variadic template function I want
Possible Duplicate: Capturing result of window.onbeforeunload confirmation dialog I want to make user confirm
Possible Duplicate: Return value from thread I want to get the free memory of
Possible Duplicate: Call Python From PHP And Get Return Code probably a very stupid
Possible Duplicate: PHP MySQL multiple search query using option / select HTML form tags
Possible Duplicate: mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object I want a function which can return fields in
Possible Duplicate: Extract the return type of a function without calling it (using templates?)
Possible Duplicate: PHP create a file without fopen I want to create a file
Possible Duplicate: ++ operator in Scala I want to increment an Int variable in
Possible Duplicate: Embedding DLLs in a compiled executable I want to compile my C#

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.