Admin::Users#index 中的名称错误
NameError in Admin::Users#index
当我想使用 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" =
我通过添加 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
这两个错误都与 class Recherche 有关,但我找不到问题的根源。是控制器吗?该模型?还有什么吗?
根据您的信息假设,由于此代码:
has_many :recherches, dependent: :destroy
...Rails 试图将复数 'recherches' 变成单数 'recherch',这不是您的 class - 'Recherche',如你所说。在这种情况下,您必须覆盖 Rails' 命名约定:
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'recherche', 'recherches'
end
当我想使用 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" =
我通过添加 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
这两个错误都与 class Recherche 有关,但我找不到问题的根源。是控制器吗?该模型?还有什么吗?
根据您的信息假设,由于此代码:
has_many :recherches, dependent: :destroy
...Rails 试图将复数 'recherches' 变成单数 'recherch',这不是您的 class - 'Recherche',如你所说。在这种情况下,您必须覆盖 Rails' 命名约定:
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'recherche', 'recherches'
end