Admin :: Users#index中的NameError

时间:2016-09-01 16:03:51

标签: ruby-on-rails ruby-on-rails-4 activeadmin

当我想用ActiveAdmin删除用户时,我收到以下错误:

PG::ForeignKeyViolation: ERROR: update or delete on table "users" violates foreign key constraint "fk_rails_18841639d7" on table "recherches" DETAIL: Key (id)=(5) is still referenced from table "recherches". : DELETE FROM "users" WHERE "users"."id" = $1

我通过添加has_many :recherches, dependent: :destroy来修复此问题,但现在我收到以下错误:

NameError in Admin::Users#index


Showing /home/charles/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/bundler/gems/activeadmin-0a5a15b88bff/app/views/active_admin/resource/index.html.arb where line #2 raised:

uninitialized constant User::Recherch

这两个错误都与Recherche类有关,但我找不到问题的来源。是控制器吗?该模型?还有什么吗?

1 个答案:

答案 0 :(得分:1)

假设您的信息,由于此代码:

has_many :recherches, dependent: :destroy

... Rails试图将复数'recherches'变成一个单独的'recherch',这不是你班级的名字 - 'Recherche',正如你所说的那样。在这种情况下,您必须覆盖Rails的命名约定:

# config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'recherche', 'recherches'
end