我最近從v.0.5.1升級了ActiveAdmin。到v.0.6.2。我運行生成器來升級我的配置並將設置與現有文件合併。將ActiveAdmin升級到v.0.6.2後的RoutingError
rails generate active_admin:install User
ActiveAdmin接口似乎正在工作。但是我不能再成功運行以前工作過的規格。我收到一個ActionController::RoutingError
:
Failure/Error: visit '/users/sign_out'
ActionController::RoutingError:
No route matches [GET] "https://stackoverflow.com/users/sign_out"
以下規範作爲一個例子,討論失敗的行爲:
# spec/features/users/active_admin_spec.rb
require 'spec_helper'
describe 'Active Admin' do
before(:all) do
I18n.locale = :en
end
it "rejects a reqular user" do
@user = create(:user)
visit '/users/sign_out'
visit '/users/sign_in'
fill_in I18n.t('devise.sessions.new.email'), with: @user.email
fill_in I18n.t('devise.sessions.new.password'), with: @user.password
click_button I18n.t('devise.sessions.new.sign_in')
visit "/admin"
expect(page).not_to have_content "Dashboard"
expect(page).to have_content "Unauthorized Access!"
end
end
...
# config/routes.rb
MyApp::Application.routes.draw do
namespace :api, defaults: {format: :json} do
namespace :v1 do
resources :sessions, only: [:create, :destroy]
resources :users, only: [:create]
end
end
# Configuration when using ActiveAdmin v.0.5.1
# devise_for :users, controllers: { sessions: "sessions" }
config = ActiveAdmin::Devise.config
config[:controllers][:sessions] = "sessions"
devise_for :users, config
ActiveAdmin.routes(self)
root :to => "home#index"
end
這是rake routes
相關部分之前升級:
new_user_session GET /users/sign_in(.:format) sessions#new
user_session POST /users/sign_in(.:format) sessions#create
destroy_user_session DELETE /users/sign_out(.:format) sessions#destroy
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
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
admin_root /admin(.:format) admin/dashboard#index
admin_dashboard /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
admin_user GET /admin/users/:id(.:format) admin/users#show
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
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
這是rake routes
相關部分升級後:
new_user_session GET /admin/login(.:format) sessions#new
user_session POST /admin/login(.:format) sessions#create
destroy_user_session DELETE|GET /admin/logout(.:format) sessions#destroy
user_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_user_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_user_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PUT /admin/password(.:format) active_admin/devise/passwords#update
cancel_user_registration GET /admin/cancel(.:format) devise/registrations#cancel
user_registration POST /admin(.:format) devise/registrations#create
new_user_registration GET /admin/sign_up(.:format) devise/registrations#new
edit_user_registration GET /admin/edit(.:format) devise/registrations#edit
PUT /admin(.:format) devise/registrations#update
DELETE /admin(.:format) devise/registrations#destroy
user_confirmation POST /admin/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /admin/confirmation/new(.:format) devise/confirmations#new
GET /admin/confirmation(.:format) devise/confirmations#show
admin_root /admin(.:format) admin/dashboard#index
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
admin_user GET /admin/users/:id(.:format) admin/users#show
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
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
它似乎忽視了SessionsController
。
我使用Devise v.2.2.7。
授權錯誤
我只注意到這個配置允許訪問ActiveAdmin非管理員用戶。所以還有更多需要解決的地方。以常規用戶身份登錄後訪問/admin
以嘗試自己。
已解決授權問題
ActiveAdmin v.0.6.2從未出現過問題。我只是簡單地破壞了我原來設置的配置。那時我按照how to set up ActiveAdmin and Devise with a single user model的教程。運行rails generate active_admin:install User
當產生
# config/initializers/active_admin.rb
config.authentication_method = :authenticate_user!
這種配置:基本上,我意外地取代了下列參數:
# config/initializers/active_admin.rb
config.authentication_method = :authenticate_active_admin_user!
與此有關。
最後,我可以告訴大家,Leger has served the correct configuration。我很高興接受你的回答,因爲現在一切正在發揮作用(據我所知)。
當我更改訂單時收到相同的錯誤。 – JJD
關於限制訪問非管理員,請查看http://stackoverflow.com/questions/9415884/how-to-limit-acces-to-active-admin-to-admin-users希望它有幫助 – Leger