4

指示に従って Rails_Admin をインストールし、Devise も使用しています。「/admin」に移動しようとすると、次のエラーが表示されます。

Routing Error

No route matches {:controller=>"home"}

ここに私のroutes.rbがあります:

Ot::Application.routes.draw do

  resources :badgeships
  resources :badges
  resources :profiles
  resources :universities
  resources :degrees
  resources :jobs
  resources :resources
  resources :communities
  resources :networks

  resources :topics do
        resources :posts
  end

  get 'topics/tag/:tag', to: 'topics#index', as: :topic_tag

  get 'resources/tag/:tag', to: 'resources#index', as: :resource_tag

  root :to => 'home#index'

  devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}

  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

end

これが私の rails_admin.rb 初期化子です:

RailsAdmin.config do |config|
  config.main_app_name = ["Cool app", "BackOffice"]
  # or somethig more dynamic
  config.main_app_name = Proc.new { |controller| [ "Cool app", "BackOffice - #{controller.params[:action].try(:titleize)}" ] }
end

rails_admin を適切に動作させる方法について何か考えはありますか?

更新: これが私のレーキルートです:

[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
              badgeships GET    /badgeships(.:format)                      badgeships#index
                         POST   /badgeships(.:format)                      badgeships#create
           new_badgeship GET    /badgeships/new(.:format)                  badgeships#new
          edit_badgeship GET    /badgeships/:id/edit(.:format)             badgeships#edit
               badgeship GET    /badgeships/:id(.:format)                  badgeships#show
                         PUT    /badgeships/:id(.:format)                  badgeships#update
                         DELETE /badgeships/:id(.:format)                  badgeships#destroy
                  badges GET    /badges(.:format)                          badges#index
                         POST   /badges(.:format)                          badges#create
               new_badge GET    /badges/new(.:format)                      badges#new
              edit_badge GET    /badges/:id/edit(.:format)                 badges#edit
                   badge GET    /badges/:id(.:format)                      badges#show
                         PUT    /badges/:id(.:format)                      badges#update
                         DELETE /badges/:id(.:format)                      badges#destroy
                profiles GET    /profiles(.:format)                        profiles#index
                         POST   /profiles(.:format)                        profiles#create
             new_profile GET    /profiles/new(.:format)                    profiles#new
            edit_profile GET    /profiles/:id/edit(.:format)               profiles#edit
                 profile GET    /profiles/:id(.:format)                    profiles#show
                         PUT    /profiles/:id(.:format)                    profiles#update
                         DELETE /profiles/:id(.:format)                    profiles#destroy
            universities GET    /universities(.:format)                    universities#index
                         POST   /universities(.:format)                    universities#create
          new_university GET    /universities/new(.:format)                universities#new
         edit_university GET    /universities/:id/edit(.:format)           universities#edit
              university GET    /universities/:id(.:format)                universities#show
                         PUT    /universities/:id(.:format)                universities#update
                         DELETE /universities/:id(.:format)                universities#destroy
                 degrees GET    /degrees(.:format)                         degrees#index
                         POST   /degrees(.:format)                         degrees#create
              new_degree GET    /degrees/new(.:format)                     degrees#new
             edit_degree GET    /degrees/:id/edit(.:format)                degrees#edit
                  degree GET    /degrees/:id(.:format)                     degrees#show
                         PUT    /degrees/:id(.:format)                     degrees#update
                         DELETE /degrees/:id(.:format)                     degrees#destroy
                    jobs GET    /jobs(.:format)                            jobs#index
                         POST   /jobs(.:format)                            jobs#create
                 new_job GET    /jobs/new(.:format)                        jobs#new
                edit_job GET    /jobs/:id/edit(.:format)                   jobs#edit
                     job GET    /jobs/:id(.:format)                        jobs#show
                         PUT    /jobs/:id(.:format)                        jobs#update
                         DELETE /jobs/:id(.:format)                        jobs#destroy
               resources GET    /resources(.:format)                       resources#index
                         POST   /resources(.:format)                       resources#create
            new_resource GET    /resources/new(.:format)                   resources#new
           edit_resource GET    /resources/:id/edit(.:format)              resources#edit
                resource GET    /resources/:id(.:format)                   resources#show
                         PUT    /resources/:id(.:format)                   resources#update
                         DELETE /resources/:id(.:format)                   resources#destroy
             communities GET    /communities(.:format)                     communities#index
                         POST   /communities(.:format)                     communities#create
           new_community GET    /communities/new(.:format)                 communities#new
          edit_community GET    /communities/:id/edit(.:format)            communities#edit
               community GET    /communities/:id(.:format)                 communities#show
                         PUT    /communities/:id(.:format)                 communities#update
                         DELETE /communities/:id(.:format)                 communities#destroy
                networks GET    /networks(.:format)                        networks#index
                         POST   /networks(.:format)                        networks#create
             new_network GET    /networks/new(.:format)                    networks#new
            edit_network GET    /networks/:id/edit(.:format)               networks#edit
                 network GET    /networks/:id(.:format)                    networks#show
                         PUT    /networks/:id(.:format)                    networks#update
                         DELETE /networks/:id(.:format)                    networks#destroy
             topic_posts GET    /topics/:topic_id/posts(.:format)          posts#index
                         POST   /topics/:topic_id/posts(.:format)          posts#create
          new_topic_post GET    /topics/:topic_id/posts/new(.:format)      posts#new
         edit_topic_post GET    /topics/:topic_id/posts/:id/edit(.:format) posts#edit
              topic_post GET    /topics/:topic_id/posts/:id(.:format)      posts#show
                         PUT    /topics/:topic_id/posts/:id(.:format)      posts#update
                         DELETE /topics/:topic_id/posts/:id(.:format)      posts#destroy
                  topics GET    /topics(.:format)                          topics#index
                         POST   /topics(.:format)                          topics#create
               new_topic GET    /topics/new(.:format)                      topics#new
              edit_topic GET    /topics/:id/edit(.:format)                 topics#edit
                   topic GET    /topics/:id(.:format)                      topics#show
                         PUT    /topics/:id(.:format)                      topics#update
                         DELETE /topics/:id(.:format)                      topics#destroy
               topic_tag GET    /topics/tag/:tag(.:format)                 topics#index
            resource_tag GET    /resources/tag/:tag(.:format)              resources#index
                    root        /                                          home#index
        new_user_session GET    /users/login(.:format)                     devise/sessions#new
            user_session POST   /users/login(.:format)                     devise/sessions#create
    destroy_user_session DELETE /users/logout(.:format)                    devise/sessions#destroy
 user_omniauth_authorize        /users/auth/:provider(.:format)            devise/omniauth_callbacks#passthru {:provider=>/facebook/}
  user_omniauth_callback        /users/auth/:action/callback(.:format)     devise/omniauth_callbacks#(?-mix:facebook)
           user_password POST   /users/password(.:format)                  devise/passwords#create
       new_user_password GET    /users/password/new(.:format)              devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)             devise/passwords#edit
                         PUT    /users/password(.:format)                  devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                    devise/registrations#cancel
       user_registration POST   /users(.:format)                           devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                   devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                      devise/registrations#edit
                         PUT    /users(.:format)                           devise/registrations#update
                         DELETE /users(.:format)                           devise/registrations#destroy
             rails_admin        /admin                                     RailsAdmin::Engine

Routes for RailsAdmin::Engine:
    dashboard GET         /                                      rails_admin/main#dashboard
        index GET|POST    /:model_name(.:format)                 rails_admin/main#index
          new GET|POST    /:model_name/new(.:format)             rails_admin/main#new
       export GET|POST    /:model_name/export(.:format)          rails_admin/main#export
  bulk_delete POST|DELETE /:model_name/bulk_delete(.:format)     rails_admin/main#bulk_delete
history_index GET         /:model_name/history(.:format)         rails_admin/main#history_index
  bulk_action POST        /:model_name/bulk_action(.:format)     rails_admin/main#bulk_action
         show GET         /:model_name/:id(.:format)             rails_admin/main#show
         edit GET|PUT     /:model_name/:id/edit(.:format)        rails_admin/main#edit
       delete GET|DELETE  /:model_name/:id/delete(.:format)      rails_admin/main#delete
 history_show GET         /:model_name/:id/history(.:format)     rails_admin/main#history_show
  show_in_app GET         /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app

rails_admin のインストール方法は次のとおりです。

    rails g rails_admin:install
        SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.9/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

           -  Hello, RailsAdmin installer will help you set things up!
           -  I need to work with Devise, let's look at a few things first:
           -  Checking for a current installation of devise...
           -  Found it!
           -  Looks like you've already installed it, good!
           ?  Where do you want to mount rails_admin? Press <enter> for [admin] > manage
        gsub  config/routes.rb
       route  mount RailsAdmin::Engine => '/manage', :as => 'rails_admin'
           -  And you already set it up, good! We just need to know about your user model name...
           -  We found 'user' (should be one of 'user', 'admin', etc.)
           ?  Correct Devise model name if needed. Press <enter> for [user] > User
           -  Now setting up devise with user model name 'User':
    generate  devise
        SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
        This poses a security threat. It is strongly recommended that you
        provide a secret to prevent exploits that may be possible from crafted
        cookies. This will not be supported in future versions of Rack, and
        future versions will even invalidate your existing user cookies.

        Called from: /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/actionpack-3.2.9/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

      invoke  active_record
      create    db/migrate/20130214195616_add_devise_to_users.rb
      insert    app/models/user.rb
       route  devise_for :users
           -  Now you'll need an initializer...
           -  You already have a config file. You're updating, heh? I'm generating a new 'rails_admin.rb.example' that you can review.
      create  config/initializers/rails_admin.rb.example
/Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in `block in source_reflection': undefined method `klass' for nil:NilClass (NoMethodError)
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in `collect'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in `source_reflection'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:375:in `rescue in foreign_key'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.9/lib/active_record/reflection.rb:373:in `foreign_key'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:292:in `association_foreign_key_lookup'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:72:in `block in associations'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:65:in `map'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/adapters/active_record.rb:65:in `associations'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields/factories/association.rb:6:in `block in <top (required)>'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `call'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `block (2 levels) in factory'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `each'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `find'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:54:in `block in factory'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:50:in `each'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/fields.rb:50:in `factory'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:130:in `_fields'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:128:in `_fields'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:108:in `all_fields'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/rails_admin/config/has_fields.rb:83:in `fields'
    from (erb):64:in `block in template'
    from (erb):53:in `map'
    from (erb):53:in `template'
    from /Users/iyerushalmi/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/erb.rb:838:in `eval'
    from /Users/iyerushalmi/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/erb.rb:838:in `result'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/file_manipulation.rb:117:in `block in template'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:54:in `call'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:54:in `render'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:63:in `open'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:63:in `block in invoke!'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/empty_directory.rb:133:in `call'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/empty_directory.rb:133:in `invoke_with_conflict_check'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:61:in `invoke!'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions.rb:95:in `action'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/create_file.rb:26:in `create_file'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/actions/file_manipulation.rb:116:in `template'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/rails_admin-0.4.4/lib/generators/rails_admin/install_generator.rb:66:in `install'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/task.rb:27:in `run'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:120:in `invoke_task'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `block in invoke_all'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `each'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `map'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/invocation.rb:126:in `invoke_all'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/group.rb:238:in `dispatch'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/thor-0.17.0/lib/thor/base.rb:434:in `start'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.9/lib/rails/generators.rb:171:in `invoke'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.9/lib/rails/commands/generate.rb:12:in `<top (required)>'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
    from /Users/iyerushalmi/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.9/lib/rails/commands.rb:29:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
4

5 に答える 5

6

編集:修正が見つかりました。この SO ディスカッションを参照してください。

メインの ApplicationController に入り、変更します

rescue_from CanCan::AccessDenied do |e|
  redirect_to root_path, alert: e.message
end

rescue_from CanCan::AccessDenied do |e|
  redirect_to '/', alert: e.message
end

Rails は間違ったルーティング テーブルで名前を探しているため、シンボリック パス名を指定すると RoutingException が発生ます。リテラル ルート パスを指定すると、ルックアップがバイパスされ、メイン アプリケーションの ApplicationController が最初に処理できるようになります。これはあなたが望むものです。

以下の元の投稿hr


同様のエラーが発生しました。管理者以外のユーザーが「/admin」ルートにアクセスすると、ActiveAdmin+CanCan がそのユーザーを追い出そうとします。(ちなみに、Gem を追加すると、はるかに読みやすいエラー レポートが得られますbetter_errors。) 例外レポートが表示され、ルーティング エラーが発生した時点でローカル変数に正しいエラー メッセージが表示されます。

また、better_errors の「ライブ シェル」のおかげで、RoutingError を生成する ActionController がRailsAdmin::MainController. これは、エンジンのルートパスではなく、アプリケーションのルート パスにリダイレクトするように RailsAdmin に指示する方法を理解する必要があることを示唆しています。

于 2013-03-19T07:12:14.647 に答える
1

ルーティングが機能しない理由は、注入したためです

mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

ファイルの下部にありroutes.rbます。ルートは上から順に優先されることを理解してください。URL がルーティングされると、リストの一番上から下に移動します。一致するルートが見つかるとすぐに、Rails はそれを適切なコントローラーとアクションに送信します。

通常、サードパーティ API を API リストの一番上に移動するのがベスト プラクティスだと思います。競合の問題が発生した場合は、自分で作成したルートを変更できます。はるかに簡単に対処できます。

そこで、Devise と RailsAdmin のルートを一番上に移動して、何が得られるか教えてください。

于 2013-02-13T18:23:03.930 に答える
0

ドキュメントで説明されているように、メイン アプリ ルートを参照するために使用main_appします。routes.rb

class ApplicationController < ActionController::Base
  rescue_from CanCan::AccessDenied do |exception|
    redirect_to main_app.root_path, :alert => exception.message
  end
end
于 2016-05-20T15:57:16.023 に答える
0

デバイスと管理ルートをルート ファイルの先頭に移動してみてください。

于 2013-02-13T12:37:54.383 に答える
0

同じ問題が発生していますが、ユーザー モデルでサインインしている場合にのみ発生します。サインインしていない場合は、サインイン ページにリダイレクトされます。

アップデート

私に起こったことは、私のユーザー モデルが:manage、ダッシュボードがアクセスするリソースに許可されていないということでした。

この承認を含めると、管理パネルが機能しました。

于 2013-04-11T14:22:50.520 に答える