Reputation: 682
When i want to delete a user with ActiveAdmin, i got the error below :
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
I fixed this by adding has_many :recherches, dependent: :destroy
but now i get the following error :
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
Both errors are related to the class Recherche but i can't find where the problem comes from. Is is the controller? The model? Anything else?
Upvotes: 1
Views: 1153
Reputation: 1783
Assuming from your information, because of this code:
has_many :recherches, dependent: :destroy
...Rails is trying to turn the plural 'recherches' into a singular 'recherch', which is not the name of your class - 'Recherche', as you called it. In this case, you have to override Rails' naming conventions:
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'recherche', 'recherches'
end
Upvotes: 0