【问题标题】:activeadmin sortable works with sqlite but not postgresactiveadmin sortable 适用于 sqlite 但不适用于 postgres
【发布时间】:2017-03-23 19:49:18
【问题描述】:

我正在使用 activeadmin。我正在尝试为一个人制作一个 activeadmin 页面。一个人belongs_to :team 和一个团队has_many :people。在使用 sqlite 开发时,以下代码完美运行:

ActiveAdmin.register Person, as: "vc" do
    index do
        column :team, sortable: :team
    end
    def scoped_collection
        p = Person.with_any_role(*Person.value_consumer_role_names).collect(&:id)
        Person.includes(:team).where(id: p)
    end
end

但是,在使用 Heroku 和 Postgresql 进行生产时,我收到以下错误:

ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column "team" does not exist

我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails postgresql activerecord activeadmin ruby-on-rails-5


    【解决方案1】:

    在列行中,您需要引用团队表,而不是模型:

    column :team, sortable: 'teams.name'
    

    【讨论】:

      猜你喜欢
      • 2011-12-24
      • 1970-01-01
      • 2011-03-20
      • 2016-11-25
      • 1970-01-01
      • 2015-01-22
      • 2020-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多