为我的select_tag添加标题

时间:2016-09-29 13:38:55

标签: ruby-on-rails ruby-on-rails-4

我正在尝试为我的select_tags添加标题 我希望有类似Select a user的内容,然后所有用户都显示在下面...现在我有了第一个用户的名字......我不希望这样...... 有什么建议吗?我找不到任何符合我观点的东西......

感谢您的帮助

=form_tag tutos_path, :method => 'get' do 
        =select_tag :select, options_for_select(User.order('nickname ASC').all.map{|u| u.nickname}, params[:select])
        =submit_tag "Select", class:"btn btn-xs btn-default btn-search"

2 个答案:

答案 0 :(得分:2)

使用include_blank选项:

select_tag :select,
           options_for_select(User.order('nickname ASC').all.map{|u| u.nickname}, params[:select]),
           { include_blank: 'Select a user' }

其他选项是使用prompt。有关select_tag的更多可用选项,请参阅docs

答案 1 :(得分:0)

试试这个,在select_tag

中添加提示选项
=select_tag :select,
options_for_select(User.order('nickname ASC').all.map{|u| u.nickname},
params[:select]), prompt: "Select a user"