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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:36:43+00:00 2026-06-02T11:36:43+00:00

There are so many results for this search on google, and it’s even asked

  • 0

There are so many results for this search on google, and it’s even asked at SO – but the solutions discussed so far are not helping me. Here’s the issue: I have a form_for @company |f| and I am using f.collection_select for company_status_id – but when the form loads, I want the actual company status selected if it is set. Through the debugger I know, that it’s been set, yet I am getting a default value displayed there. Here’s the code:

= puts @company.company_status_id
= f.collection_select :company_status_id, ListCache.company_statuses, :id, :name, {:prompt => @select_value}

Here’s the generated htmnl

<select id="company_company_status_id" prompt="-Select-" name="company[company_status_id]">
<option value="1">-Not Available-</option>
<option value="2">Active</option>
<option value="3">Bankrupt</option>
<option value="4">Acquired</option>
</select>

And the conditions remain the same even if I do:

f.collection_select :company_status_id, ListCache.company_statuses, :id, :name, {:prompt => @select_value, :selected => :selected => @company.company_status}

Or

f.collection_select :company_status_id, ListCache.company_statuses, :id, :name, {:prompt => @select_value, :selected => @company.company_status}
  • 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-02T11:36:44+00:00Added an answer on June 2, 2026 at 11:36 am

    This is what I finally did:

    f.collection_select :company_status_id, ListCache.company_statuses, :id, :name, {:prompt => @select_value, :selected => @company.company_status_id.to_i}
    

    I read on of the answers on a similar question that collection_select automatically selects the selected value by making comparisons of what is passed with the attributes of collection. apparently there was a difference of their types, and comparing the int from CompanyStatus to the int of @company.company_status_id.to_i worked out. Though @company.company_status_id is supposed to be int as well. I can see that in the db. Anyway, it this line of code worked.

    If anyone can exaplain, I will be much thankful!

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

Sidebar

Related Questions

I know this question was asked many times, but still my problem is not
I'd like to achieve this result there are many tutorial around like this but
There are many errors here in SO, but this scenario I think its different.
There are many questions like this but I can't find one that seems to
When looking at a Google search results page, such as http://www.google.com/search?q=test , is there
There are so many services now, and a lot of search results about the
There are many similar questions, but I didn't find one that gets straight to
I saw that there's many, many thread about this on the web, also in
Apologies if I am not wording this correctly but what I have at the
I have this script which allows to display Bing search results: JsFiddle Demo The

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.