19

Rails入門に忠実にブログを作成しました。そして、こちらのチュートリアルに従って、ActiveAdmin を試してみました: http://activeadmin.info/documentation.html

Post および Tag モデル (ログインして作成/追加/編集したもの) では正常に機能していますが、Comment モデルでは機能していません。

rails generate active_admin:resource Comment

create  app/admin/comments.rb

次に、サーバーを起動しようとすると、次のようになります。

rails server=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server Exiting /usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:116:in
`find_or_build_resource': Tried to
register Comment as Comment but
already registered to Comment
(ActiveAdmin::ResourceMismatchError)
    from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin/namespace.rb:45:in
`register'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:141:in
`register'  from
/Users/myusername/Projects/RoR/blog/app/admin/comments.rb:1:in
`<top (required)>'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`block in load'     from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`block in load_dependency'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in
`new_constants_in'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`load_dependency'   from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in
`block in load!'    from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in
`each'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:185:in
`load!'     from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:212:in
`routes'    from
/Users/myusername/Projects/RoR/blog/config/routes.rb:2:in
`block in <top (required)>'     from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:233:in
`instance_exec'     from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/routing/route_set.rb:233:in
`draw'  from
/Users/myusername/Projects/RoR/blog/config/routes.rb:1:in
`<top (required)>'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`block in load'     from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`block in load_dependency'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in
`new_constants_in'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`load_dependency'   from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in
`load'  from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in `block in reload_routes!'    from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in `each'   from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:127:in `reload_routes!'     from
/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.2.2/lib/active_admin.rb:123:in
`block in setup'    from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:420:in
`_run_prepare_callbacks'    from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/callbacks.rb:40:in
`initialize'    from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in
`new'   from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:33:in
`build'     from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`block in build'    from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`each'  from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`inject'    from
/usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.7/lib/action_dispatch/middleware/stack.rb:79:in
`build'     from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:162:in `app'    from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application/finisher.rb:35:in
`block in <module:Finisher>'    from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'     from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'   from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `block in run_initializers'     from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'  from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'  from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'    from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in
`method_missing'    from
/Users/myusername/Projects/RoR/blog/config/environment.rb:5:in
`<top (required)>'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in
`require'   from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in
`block in require'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`block in load_dependency'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:596:in
`new_constants_in'  from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:225:in
`load_dependency'   from
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in
`require'   from
/Users/myusername/Projects/RoR/blog/config.ru:3:in
`block in <main>'   from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in
`instance_eval'     from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in
`initialize'    from
/Users/myusername/Projects/RoR/blog/config.ru:1:in
`new'   from
/Users/myusername/Projects/RoR/blog/config.ru:1:in
`<main>'    from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in
`eval'  from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in
`parse_file'    from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:162:in
`app'   from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:248:in
`wrapped_app'   from
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:213:in
`start'     from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands/server.rb:65:in `start'   from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:30:in
`block in <top (required)>'     from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in
`tap'   from
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in
`<top (required)>'  from
script/rails:6:in `require'     from
script/rails:6:in `<main>'

あなたの助けをいただければ幸いです。

4

4 に答える 4

45

バグのように見えます (ActiveAdmin にはComment既に独自の組み込みモデル/クラスがあります): https://github.com/gregbell/active_admin/issues/64

考えられる回避策はComment、 in 内でモデルに別の名前を付けることapp/admin/comments.rbです。

ActiveAdmin.register Comment, :as => "PostComment" do
于 2011-06-06T13:36:40.320 に答える
5

これを試して

ターミナルで実行

rails g active_admin:resource ActiveAdmin::Comment

app/admin/active_admin_comment.rbに次の行を追加します

ActiveAdmin.register ActiveAdmin::Comment, :as => "Comment" do
end

その後、config/initializers/active_adminを編集します

[...]
  config.comments_registration_name = "OldComment"
  config.show_comments_in_menu = false
[...]

app/admin/active_admin_comment.rbのコメントをカスタマイズする機会がありますが、 :updateおよび:destroyアクション を追加する解決策が見つかりませんでした。

于 2014-05-23T12:22:37.563 に答える
3

私はバージョン 1.0.0.pre で同じ問題を抱えていましたが、ありがたいことに、active_admin.rb の構成で ActiveAdmin コメントを完全に抑制することができ、上記のように独自のコメント モデルにエイリアスを設定する必要がなくなりました。

config/initializers/active_admin.rb

  ...
  # == Admin Comments
  #
  # This allows your users to comment on any resource registered with Active Admin.
  #
  # You can completely disable comments:
  config.allow_comments = false
  #

ドキュメントにも記載されています: https://github.com/gregbell/active_admin/blob/master/docs/1-general-configuration.md#comments

于 2014-06-23T18:17:42.123 に答える
1

ディランの答えは素晴らしいスタートです。彼に加えて、コントローラーのリソース/コレクション メソッドを上書きする必要がありました。

app/admin/comments.rb

ActiveAdmin.register Comment, as: 'QuestionComment' do
   controller do
     defaults resource_class: Comment, collection_name: 'comments', instance_name: 'comment'
   end
end

基本的に、継承されたリソースコントローラーのデフォルトを上書きしているだけです(https://github.com/josevalim/inherited_resources#overwriting-defaults

(はい、これは 1.0.0 プレリリース バージョンでも 2014 年にはまだ問題ですが、github の問題を読んで修正したいと考えているようです)

于 2014-03-06T21:45:17.050 に答える