[英]Choose order Rails records, or show “ ALL ” in first
I'm searching for a method to choose the first record of a grouped_collection_select, or to show " ALL " in the first choice. 我正在寻找一种选择grouped_collection_select的第一条记录或在第一选择中显示“ ALL”的方法。
<%= f.collection_select :marque_id, Marque.all, :id, :name_upper, :include_blank => 'ALL', :prompt => 'Mark' %>
<%= f.grouped_collection_select :modele_id, Marque.all, :modeles, :name_upper, :id, :name_upper, :prompt => 'Model', :include_blank => 'ALL' %>
The " :include_blank => 'ALL' " work fine for the collection_select, but not for the grouped_collection_select. “:include_blank =>'ALL'”对于collection_select而言工作正常,但对于grouped_collection_select而言则无效。
For the grouped_collection_select, it only show a blank field at the first place. 对于grouped_collection_select,它仅在第一位置显示空白字段。
I tried to put a blank record in the database, or to put " ALL " in the database with a lot of symbol like : " # ALL # " ... Didn't work with number ( 147, 156, 159 [...], # ALL #,...) 我试图在数据库中放入空白记录,或在数据库中放入带有许多符号的“ ALL”,例如:“#ALL#” ...不适用于数字(147、156、159 [。 。],#ALL#,...)
EDIT: 编辑:
Or maybe I can add a field in each subcategories, and define that "First" ? 或者,也许我可以在每个子类别中添加一个字段,然后定义“ First”? But I want to keep everything ordering by "name ASC". 但我想按“名称ASC”保持所有顺序。
I already put 我已经放了
default_scope order('name ASC')
in my Modele.rb 在我的Modele.rb中
I found how to do what I wanted. 我找到了想做的事。
I just had to add 我只需要添加
$('#search_modele_id').preprend('<option value="" selected="selected">ALL</option>');
to my jQuery code, and put the value as " BLANK " (really important in my case). 到我的jQuery代码中,然后将值设置为“ BLANK”(对我而言非常重要)。
And put 并把
:include_blank => true
Instead of 代替
:include_blank => 'ALL'
In the search form 在搜索表单中
Problem solved. 问题解决了。
Thanks anyway! 不管怎么说,还是要谢谢你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.