Rails and forms: drop down with range of numbers and Unlimited

前端 未结 2 737
深忆病人
深忆病人 2021-01-18 09:39

I have this right now:

<%= f.select :credit, (0..500) %>

This will result in this:

2条回答
  •  北海茫月
    2021-01-18 09:48

    If I understand the question correctly, you can use options_for_select and prompt to do this a little more cleanly than what is shown in the selected answer:

    <%= f.select :credit, options_for_select(0..500), { prompt: "No Limit" } %>
    

    See the docs here: http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select

提交回复
热议问题