对每个 do 循环(字母)红宝石轨道进行排序



是否可以在下面的代码中对字母表进行排序,还是必须在控制器中执行此操作?

下面的代码显示了所有网站,但我想按字母表排序并在离线网站上排序。因此,离线网站始终处于领先地位。

<% @websites.each_with_index do |website, index| %>

假设你有像offline: true这样的字段,name: <string>Website模型中:

<% @websites.order(offline: :desc, name: :desc).each_with_index do |website, index| %>

但是,您可能会在控制器中检索@websites,因此最好在控制器/模型范围/视图外的任何位置应用该order条件。

<% @websites.sort.each_with_index do |website, index| %>@websites是否是一个数组。<% @websites.order('title ASC').each_with_index do |website, index| %>如果活动记录,这里的标题是指我们要排序的列。

最新更新