在 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 do
、show do
和 edit 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/