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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:55:48+00:00 2026-05-26T05:55:48+00:00

I would like to create a simple drop down list with static values which

  • 0

I would like to create a simple drop down list with static values which I could reuse anywhere in my Ruby on Rails application in a form. The drop down list is really simple, something like this:

<select>
    <option value="5">5 minutes</option>
    <option value="15">15 minutes</option>
    <option value="30">30 minutes</option>
    <option value="60">1 hour</option>
</select>

What is the most convenient way in Rails to create a “control” (I don’t know if this term is even used in Rails) like this and be able to use it anywhere in a form and bind it to a property of a model class?

UPDATE: Thanks for the answers, those seems to be really nice solutions.

However, would it be possible to extend the class that the form_for returns (not sure which one, is it FormHelper or FormBuilder?), in order to be able to do this in a view:

<%= form_for(@myObj) do |f| %>
    <%= f.select_duration :duration %>
<% end %>

I started googling for how to extend the form helper, but could not figure it out yet.

UPDATE2: I can not answer my own question, so I put it here.

Finally figured out how to do it. Created a form_helper.rb file in app/helpers, and extended FormBuilder with the following code:

module FormHelper
    def self.included(base)
        ActionView::Helpers::FormBuilder.instance_eval do
            include FormBuilderMethods
        end
    end

    DURATIONS = [["5 Minutes", 5], ["15 minutes", 15], ["30 minutes", 30],["1 hour", 60]]
    module FormBuilderMethods
        def select_duration(method)
            @template.select @object_name,  method, @template.options_for_select(DURATIONS, @object.reminderTimeMinutes ? DURATIONS[@object.reminderTimeMinutes] : DURATIONS[0])
        end
    end
end

The last thing I am not sure about is whether it is a correct place for the DURATIONS constant (I am quite new to ruby, and ruby on rails).

  • 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-26T05:55:49+00:00Added an answer on May 26, 2026 at 5:55 am

    Create a .rb file in app/initializers that creates your options as an array

    DURATIONS = [["5 Minutes", 5], ["15 minutes", 15], ["30 minutes", 30],["1 hour", 60]]
    

    Then, in the _forms in which you want to make use of these options,

    <div class="field">
      <b>Choose a duration</b><br />
      <%= f.select :duration, options_for_select(DURATIONS, @my_table.duration ? DURATIONS[@my_table.duration] : DURATIONS[0]) %>
    </div>
    

    Good luck.

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

Sidebar

Related Questions

I would like to create a simple file format/DSL which would allow my users
I would like to create a simple designer which looks like visual studio. Specifically,
I would like to create simple objects at runtime (textbox, label, etc) and add
I would like to create a simple control that inherits from HeaderedContentControl, and has
I would like to create a simple XMPP client in java that shares his
For a web application, I would like to create a simple but effective licensing
I would like to create an online, simple WYSIWYG drawing editor allowing people to
If you populate a drop down list of possible values, you only want the
Using the Northwind sample: I would like to create an insert trigger on the
I would like create my own collection that has all the attributes of python

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.