There is such a select:

<%= select_tag('group_by', options_for_select([[]] + @query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}, @query.group_by)) %> 

Tell me how to add the :selected attribute to it so that it is empty by default, i.e. :selected => "" ?

    1 answer 1

    Add the attribute include_blank: true third parameter of the helper select_tag , as a result you will automatically add an empty line to the beginning, which will be selected by default

     <%= select_tag('group_by', options_for_select(@query.groupable_columns.collect {|c| [c.caption, c.name.to_s]}), include_blank: true) %> 
    • did not work, anyway the last value in this list is put by default. In this case, the empty value is there by default, but in third place: <select name="group_by" id="group_by" selected="selected"><option value="cf_107">hidden</option><option value="cf_36">SMS</option><option value="">&nbsp;</option><option value="author">Автор</option><option selected="selected" value="cf_85">№ задачи у вендора</option></select> - S.Ivanov
    • @ S.Ivanov because you have the value \ @ query.group_by not nil, i.e. the selected value already exists as soon as it becomes nil the first row is selected. I removed the second argument in the example in the options_for_select helper - try loading the form without it. - cheops
    • all the same sets the last value in this select: <option selected="selected" value="cf_85">№ задачи у вендора</option></select> - S.Ivanov
    • @ S.Ivanov open the form in a new window, where there is no POST and GET data - cheops
    • so I do, in the browser I enter: redmine-new / issues opens a page where this select is selected by the last value - S.Ivanov