Rails form_for select tag with option selected

前端 未结 2 408
礼貌的吻别
礼貌的吻别 2021-02-05 14:04

I am using a form_for to update a user profile.

As part of the form I am using a select menu. The menu is filled from an array ie,

STATUS = [[\'Active\',         


        
相关标签:
2条回答
  • 2021-02-05 14:27
    <%= f.select(:status, options_for_select(STATUS, :selected => params[:status])) %>
    

    should be written as

    <%= f.select :status, STATUS %>
    
    0 讨论(0)
  • 2021-02-05 14:38

    In the case that params doesn't do it for you, try

    <%= f.select(:status, options_for_select(STATUS, :selected => f.object.status)) %>
    
    0 讨论(0)
提交回复
热议问题