Rails 4.2设计+ ActiveAdmin,重定向到sign_in页面

时间:2015-02-12 20:16:06

标签: ruby-on-rails ruby ruby-on-rails-4 devise activeadmin

Stack上有关于这个问题的各种问题,但没有一个解决方案对我有用。

我在Rails 4.2上设置了Devise和ActiveAdmin。我可以/admin登录管理仪表板,但我会立即重定向到new_user_session_path。在此之后,如果我访问/admin,我将以管理员身份登录,并且可以毫无问题地访问信息中心。

关于我为什么要重定向的任何想法?

谢谢。

我已在初始化程序文件夹中将此行代码添加到active_admin.rb:

config.skip_before_filter :authenticate_user!

这是日志:

Started POST "/admin/login" for 127.0.0.1 at 2015-02-13 12:43:35 -0500
Processing by ActiveAdmin::Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"kHYu9AHzbUAbs+A2JTC16P3S4tynjJmrtam++Wlze19Z4encRLdNlqm1m1q2zaU+iiXbxZhVeXQBt0IwdpsXLg==", "admin_user"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]
", "remember_me"=>"0"}, "commit"=>"Login"}
  AdminUser Load (0.4ms)  SELECT  "admin_users".* FROM "admin_users" WHERE "admin_users"."email" = $1  ORDER BY "admin_users"."id" ASC LIMIT 1  [["email", "admin@example.com"]]
   (0.2ms)  BEGIN
  SQL (0.5ms)  UPDATE "admin_users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "admin_users"."id" = $5  [["last_sign_in_at", "2015-02-13 15:20:35.802130
"], ["current_sign_in_at", "2015-02-13 17:43:35.624351"], ["sign_in_count", 15], ["updated_at", "2015-02-13 17:43:35.630808"], ["id", 1]]
   (0.8ms)  COMMIT
Redirected to http://comicbookdb.dev/comic_books
Completed 302 Found in 125ms (ActiveRecord: 1.9ms)

Processing by ComicBooksController#index as HTML
Completed 401 Unauthorized in 1ms


Started GET "/users/sign_in" for 127.0.0.1 at 2015-02-13 12:43:35 -0500
Processing by Devise::SessionsController#new as HTML

很明显,它会将我的管理员用户首先重定向到/comic_books,然后因为管理员用户未经授权而导致/users/sign_in

我不确定解决此问题的最佳方法。也许像Pundit这样的宝石会有所帮助吗?这真的开始让我疯狂。

谢谢。

这是我的路线档案:

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

  root  'static_pages#welcome'
  devise_for :users
  resources :comic_books
  resources "contacts", only: [:new, :create]

  get 'welcome'       => 'static_pages#welcome'
  get 'about'         => 'high_voltage/pages#show', id: 'about'
  get 'contact'       => 'contacts#new'

0 个答案:

没有答案