2

我刚刚安装了 ActiveAdmin,一切顺利:

gem 已安装,我运行了 install 命令。我能够访问 localhost:3000/admin 并使用文档中列出的 admin@example 和“密码”凭据登录。

但是,当我单击“登录”时,我得到以下信息:

No route matches {:action=>"show", :controller=>"users", :id=>nil}

我的 routes.rb 文件:

devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}

resources :offers

resources :users do
collection do
  get :currentoffers
end

我的 users_controller.rb:

def index
end

def show
    @user = User.find(params[:id])
end

def currentoffers
    #calls the currentoffers.js.erb file
    respond_to do |format|
        format.html
        format.js
    end
end

运行 rake 路线时得到的结果:

admin_root            /admin(.:format)                          admin/dashboard#index
batch_action_admin_admin_users POST       /admin/admin_users/batch_action(.:format) admin/admin_users#batch_action
         admin_admin_users GET        /admin/admin_users(.:format)              admin/admin_users#index
                           POST       /admin/admin_users(.:format)              admin/admin_users#create
      new_admin_admin_user GET        /admin/admin_users/new(.:format)          admin/admin_users#new
     edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)     admin/admin_users#edit
          admin_admin_user GET        /admin/admin_users/:id(.:format)          admin/admin_users#show
                           PUT        /admin/admin_users/:id(.:format)          admin/admin_users#update
                           DELETE     /admin/admin_users/:id(.:format)          admin/admin_users#destroy
           admin_dashboard            /admin/dashboard(.:format)                admin/dashboard#index
 batch_action_admin_comments POST       /admin/comments/batch_action(.:format)    admin/comments#batch_action
            admin_comments GET        /admin/comments(.:format)                 admin/comments#index
                           POST       /admin/comments(.:format)                 admin/comments#create
             admin_comment GET        /admin/comments/:id(.:format)             admin/comments#show
    new_admin_user_session GET        /admin/login(.:format)                    active_admin/devise/sessions#new
        admin_user_session POST       /admin/login(.:format)                    active_admin/devise/sessions#create
destroy_admin_user_session DELETE|GET /admin/logout(.:format)                   active_admin/devise/sessions#destroy
       admin_user_password POST       /admin/password(.:format)                 active_admin/devise/passwords#create
   new_admin_user_password GET        /admin/password/new(.:format)             active_admin/devise/passwords#new
  edit_admin_user_password GET        /admin/password/edit(.:format)            active_admin/devise/passwords#edit
                           PUT        /admin/password(.:format)                 active_admin/devise/passwords#update
          new_user_session GET        /login(.:format)                          devise/sessions#new
              user_session POST       /login(.:format)                          devise/sessions#create
      destroy_user_session DELETE     /logout(.:format)                         devise/sessions#destroy
   user_omniauth_authorize            /auth/:provider(.:format)                 devise/omniauth_callbacks#passthru {:provider=>/facebook/}
    user_omniauth_callback            /auth/:action/callback(.:format)          devise/omniauth_callbacks#(?-mix:facebook)
             user_password POST       /password(.:format)                       devise/passwords#create
         new_user_password GET        /password/new(.:format)                   devise/passwords#new
        edit_user_password GET        /password/edit(.:format)                  devise/passwords#edit
                           PUT        /password(.:format)                       devise/passwords#update
  cancel_user_registration GET        /cancel(.:format)                         devise/registrations#cancel
         user_registration POST       /                                         devise/registrations#create
     new_user_registration GET        /sign_up(.:format)                        devise/registrations#new
    edit_user_registration GET        /edit(.:format)                           devise/registrations#edit
                           PUT        /                                         devise/registrations#update
                           DELETE     /                                         devise/registrations#destroy

有谁知道我为什么会收到这个错误?在 routes.rb 文件中包含用户资源是否会干扰 ActiveAdmin?

- -更新:

# Application_controller.rb:

class ApplicationController < ActionController::Base
    protect_from_forgery

def after_sign_in_path_for(resource)
    user_path(@user)
end

end
4

3 回答 3

4

试试这个,

def after_sign_in_path_for(resource)
  user_path(resource)
end

问题在于,

 user_path(@user)

其中@user 未定义,因此为零。

于 2013-04-03T14:31:37.727 回答
3

移动这条线

ActiveAdmin.routes(self)

在这条线之上

devise_for :admin_users, ActiveAdmin::Devise.config
于 2013-04-03T14:38:09.233 回答
0

移动

ActiveAdmin.routes(self)

 devise_for :admin_users, ActiveAdmin::Devise.config

由于生成了额外的“/”路由的 ActiveAdmin 错误导致错误,该错误已在 ActiveAdmin 0.6.1 中修复,升级 ActiveAdmin 将允许修复为我们解决问题。

于 2013-10-16T10:58:36.523 回答