ruby-on-rails - rails 管理栏不存在

标签 ruby-on-rails postgresql rails-admin

在 rails admin 中编辑用户时,我得到一个列不存在。 sales和users的关系是user has_many:sales,sale belongs_to buyer,另一个belongs_to seller,写成这样

belongs_to :seller, :class_name=>User, :foreign_key=>:seller_id

ActionView::Template::Error (PG::Error: ERROR:  column sales.user_id does not exist
LINE 1: SELECT "sales".* FROM "sales"  WHERE "sales"."user_id" = 14
                                             ^
: SELECT "sales".* FROM "sales"  WHERE "sales"."user_id" = 14):
    1: = rails_admin_form_for @object, :url => edit_path(@abstract_model, @object.id), :as => @abstract_model.param_key, :html => { :method => "put", :multipart => true, :class => "form-horizontal denser", :data => { :title => @page_name } } do |form|
    2:   = form.generate :action => :update

我尝试编辑模型的配置文件 (initializers/rails_admin) 以不在展示页面上显示任何与销售相关的内容。为此,我仅向 list doshow doedit do 添加了几个测试字段(并省略了与销售有关的任何内容) > 用户模型 block 。

我不太确定要编辑什么,这样 Rails 管理员就不会尝试在销售表中查找用户 ID。

任何想法,尤其是回答,我们都将不胜感激!

最佳答案

您需要在has_many/has_one 关联上指定foreign_key

查看 Rails 文档:

:foreign_key

Specify the foreign key used for the association. By default this is guessed to be the name of this class in lower-case and "_id" suffixed. So a Person class that makes a has_many association will use "person_id" as the default :foreign_key

关于ruby-on-rails - rails 管理栏不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11873011/

相关文章:

ruby-on-rails - RSPEC 未定义局部变量或方法 `response'

ruby-on-rails - 在 rails 中间件中访问路由

ruby-on-rails - 在 Rails 中初始化 class_attribute 的正确方法是什么?

ruby-on-rails - Ruby on Rails 服务器长时间随机挂起/滞后

postgresql - PostgreSQL 计数查询优化

javascript - 在 rails_admin 仪表板上包含自定义 js 文件

ruby-on-rails - 使用 Sorcery 的 Rails 管理员

java - Cloud SQL Postgres 找不到适用于 jdbc 的驱动程序 :postgres://google/

sql - 我可以使用模来指定 postgres 中的间隔吗?

ruby-on-rails - 为自定义操作定义 Controller 似乎不起作用 Rails Admin