LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】ActiveAdmin エラー#You're trying to register 〜 対処方法

Posted at

※備忘録です。

ActiveAdminでユーザのコメントを管理したい!

利用環境
・ruby 2.7.3
・Rails 6.1.4

前提条件

gemの activeadmin はインストール済み
ユーザが投稿した内容: post テーブル
その post に対してコメント: comment テーブルを実装済み
activeadminを使ってこの comment を管理したい

エラー内容と流れ

rails g active_admin:resource Comment を実行
app/admin/comments.rb ファイルを作成
上記ファイルに permit_params :content を追加
rails s でサーバー起動

You're trying to register ActiveAdmin::Comment as Comment, 
but the existing ActiveAdmin::Resource config was built for Comment!

このようにエラーが出た。

解決方法

ActiveAdmin にすでに用意されている commentがあるのに追加で comment ファイルを作成してしまっているため。
つまり同じ comment が2つ存在してしまっているエラーとなります。
ユーザー側のコメントを comment のままで
管理者側のコメントを admin comment に変更します。

config/initializers/active_admin.rb
#  〜〜〜〜〜〜略〜〜〜〜〜〜〜
  config.comments_registration_name = 'AdminComment'
end

これでエラーは解消されました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0