1

我有一个索引管理视图,其中显示了关联的模型City。我希望能够按城市名称排序,但是当我单击列标题进行排序时,我收到以下错误:

ActiveRecord::StatementInvalid in Admin/deals#index

SQLite3::SQLException: no such column: cities.name: SELECT  "deals".* FROM "deals"  ORDER BY cities.name desc LIMIT 30 OFFSET 0

索引视图

ActiveAdmin.register Deal do
  index do
     column :id
     column :city
  end
  ...
end

模型

class Deal < ActiveRecord::Base
  belongs_to :city
end

如何按城市排序?

4

2 回答 2

2

使用 Rails 3 或 4:

index do
  column :city, :sortable=>:"cities.name"

  ...
end

然后,在同一个文件中,您需要它以便Deal查询包含City属性:

controller do
  def scoped_collection
    Deal.includes(:city)
  end

  ...
end
于 2014-09-22T18:41:58.730 回答
0

看看https://github.com/gregbell/active_admin/pull/623#issuecomment-2419393和以下评论。您必须告诉 activeadmin 如何进行排序 - 可能类似于在定义交易索引页面之前定义范围column :city, :sortable => 'cities.name'joined就像是

scope :joined, :default => true do |deals|
  deals.includes [:city]
end
于 2012-06-29T19:39:05.800 回答