Rails 3: f.select - options_for_select

后端 未结 6 1420
你的背包
你的背包 2021-01-31 16:47

I have a form on my Ruby on Rails3 Application with a drop menu, this is my current code for the select option:

<%= f.select :phone_type, options_for_select([         


        
6条回答
  •  旧巷少年郎
    2021-01-31 17:18

    Thanks to everyone who contributed an answer.

    I needed similar code for a project I'm working on and I really liked the approach Ryan Burnette took.

    This is what worked for me using Rails 4.1.0.

    <%= f.select :season, options_for_seasons, :prompt => 'Select One' %>
    

    Then I defined the options in my helper.

    def options_for_seasons
      ['Spring', 'Summer', 'Autumn', 'Winter']
    end
    

    I went with:prompt => 'Select One'because I only wanted the "Select One" option to be listed in the edit form if a season had not been previously selected.

提交回复
热议问题