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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:35:52+00:00 2026-06-10T00:35:52+00:00

I need to create a select box that goes from 1 to a number

  • 0

I need to create a select box that goes from 1 to a number defined in a active record. This number will change.

So far I know I can create a select box like this:

<%= f.select  :numbers, %w[1 2 3 4 5 6 7 8 9 10 ] %>

but what I need is something like this:

<%= f.select  :numbers, %w[1..@user.number] %>

is there a way to create a nice dynamic select box in rails or do I need to manually create select tags in html with a for loop or something like that?

Thanks

  • 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-10T00:35:53+00:00Added an answer on June 10, 2026 at 12:35 am

    You can turn a Range into an Array using the to_a method:

    <%= f.select :numbers, (1 .. @user.number).to_a %>
    

    Or you can hand f.select the raw range and it will call to_a for you:

    <%= f.select :numbers, 1 .. @user.number %>
    

    From the fine manual:

    select(object, method, choices, options = {}, html_options = {})

    Create a select tag and a series of contained option tags for the provided object and method. The option currently held by the object will be selected, provided that the object is available.

    There are two possible formats for the choices parameter, corresponding to other helpers’ output:

    • A flat collection: see options_for_select
    • A nested collection: see grouped_options_for_select

    And options_for_select says:

    options_for_select(container, selected = nil)

    Accepts a container (hash, array, enumerable, your type) and returns a string of option tags.

    A Range is an Enumerable so both f.select calls above should yield the same result.

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

Sidebar

Related Questions

I need to create a select box with query data from my Database by
I need to create an HTML drop down that will display flags of countries.
I need to add a select box next to each field in a create/update
I'm trying to create a select box drop down with a twist, Basically this
I need to create an interface where a user needs to select how many
Need to create a custom DNS name server using C which will check against
I need to create a WP site which will have multiple subjects. Each subject
I have a select box that gets generated dynamically. I want to allow users
So I've got a plugin I've been working on that takes a select box
I need to create a drop down menu in struts2 from List. How can

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.