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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:20:53+00:00 2026-05-26T15:20:53+00:00

I have this hash constant: EMPLOYEE_NUM_OPTIONS = { ‘Please, select’ => ”, ’10-50′ =>

  • 0

I have this hash constant:

 EMPLOYEE_NUM_OPTIONS = {
   'Please, select' => '',
   '10-50' => '10-50',
   '51-100' => '51-100',
   '101-500' => '101-500',
   '501-1999' => '501-1999',
   '+2000' => '2000',

}

which I want to use in Rails form as options exactly in the order it is written. Using

<%= pf.select(:employee_num, GroupProfile::EMPLOYEE_NUM_OPTIONS.sort)%>

does not give the expected result.

Thank you for your help.

  • 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-26T15:20:54+00:00Added an answer on May 26, 2026 at 3:20 pm

    When you call sort on the Hash, you will effectively convert the Hash to an array of key/value arrays and then sort those using Array#<=> which will wreck your order. Whatever you hand to pf.select should end up going through options_for_select:

    Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container where the elements respond to first and last (such as a two-element array), the “lasts” serve as option values and the “firsts” as option text. Hashes are turned into this form automatically, so the keys become “firsts” and values become lasts.

    Emphasis mine. So you should be able to say this if you’re using Ruby 1.9:

    <%= pf.select(:employee_num, GroupProfile::EMPLOYEE_NUM_OPTIONS) %>
    

    If you’re in 1.8 then you can change EMPLOYEE_NUM_OPTIONS to an array-of-arrays:

    EMPLOYEE_NUM_OPTIONS = [
       [ 'Please, select', '' ],
       [ '10-50','10-50' ],
       [ '51-100', '51-100' ],
       [ '101-500', '101-500' ],
       [ '501-1999', '501-1999' ],
       [ '+2000', '2000' ]
    ]
    

    to get the order right and hand that to pf.select. If you also need a Hash form then:

    EMPLOYEE_NUM_OPTIONS_HASH = Hash[EMPLOYEE_NUM_OPTIONS]
    

    should do the trick.

    Again, if you’re using 1.9 then you’ll have ordered Hashes already so you don’t need all this extra work.

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

Sidebar

Related Questions

Let's say I have a hash in Ruby like this: d = {1 =>
I have this hash hasha = {a => b,a_a => {x_y => sreeraj,a_b =>
I have this hash. I am trying to render in a view. Which me
I have this method to hash a string: byte[] buffer = enc.GetBytes(text); SHA1CryptoServiceProvider cryptoTransformSHA1
I have a ruby hash that looks like this { stuff_attributes => { 1
I have a simple constant hash with string keys defined: MY_CONSTANT_HASH = { 'key1'
I have this hash: h => {"67676.mpa"=>{:link=>"pool/sdafdsaff", :size=>4556}} > h.each do |key, value| >
I have a ruby hash like this h = {a => 1, b =>
I have a hash object, whose structure looks similar to this: {:category1 => {:subcategory1
I have a json hash which has a lot of keys. I retrieve this

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.