7

我正在按照 railscast 关于安装 activeadmin 的说明进行操作。安装后,我收到两个错误 -

1) sign_in 的 args 数量无效 - 所以我将我的 sign_in 方法重命名为 sign_in_user 并解决了这个问题。

然后

2) signed_in 的参数数量无效?- 所以我重命名了我的signed_in?is_signed_in 的方法?这解决了这个问题。

现在一切似乎都正常了,除了当我单击 activeadmin 中的注销按钮时,它显示“已成功注销”,但注销按钮仍位于顶部角落并且没有将我注销。

根据有类似问题的人的建议,我将这两件事添加到我的 active_admin.rb 文件中:

config.logout_link_path = :destroy_admin_user_session_path

config.logout_link_method = :delete

但仍然没有运气。这是我的耙子路线:

     admin_dashboard        /admin(.:format)                               {:action=>"index", :controller=>"admin/dashboard"}
            admin_comments GET    /admin/comments(.:format)                      {:action=>"index", :controller=>"admin/comments"}
            admin_comments POST   /admin/comments(.:format)                      {:action=>"create", :controller=>"admin/comments"}
         new_admin_comment GET    /admin/comments/new(.:format)                  {:action=>"new", :controller=>"admin/comments"}
        edit_admin_comment GET    /admin/comments/:id/edit(.:format)             {:action=>"edit", :controller=>"admin/comments"}
             admin_comment GET    /admin/comments/:id(.:format)                  {:action=>"show", :controller=>"admin/comments"}
             admin_comment PUT    /admin/comments/:id(.:format)                  {:action=>"update", :controller=>"admin/comments"}
             admin_comment DELETE /admin/comments/:id(.:format)                  {:action=>"destroy", :controller=>"admin/comments"}
    new_admin_user_session GET    /admin/login(.:format)                         {:action=>"new", :controller=>"active_admin/devise/sessions"}
        admin_user_session POST   /admin/login(.:format)                         {:action=>"create", :controller=>"active_admin/devise/sessions"}
destroy_admin_user_session DELETE /admin/logout(.:format)                        {:action=>"destroy", :controller=>"active_admin/devise/sessions"}
       admin_user_password POST   /admin/password(.:format)                      {:action=>"create", :controller=>"active_admin/devise/passwords"}
   new_admin_user_password GET    /admin/password/new(.:format)                  {:action=>"new", :controller=>"active_admin/devise/passwords"}
  edit_admin_user_password GET    /admin/password/edit(.:format)                 {:action=>"edit", :controller=>"active_admin/devise/passwords"}
       admin_user_password PUT    /admin/password(.:format)                      {:action=>"update", :controller=>"active_admin/devise/passwords"}
                     users GET    /users(.:format)                               {:action=>"index", :controller=>"users"}
                     users POST   /users(.:format)                               {:action=>"create", :controller=>"users"}
                  new_user GET    /users/new(.:format)                           {:action=>"new", :controller=>"users"}
                 edit_user GET    /users/:id/edit(.:format)                      {:action=>"edit", :controller=>"users"}
                      user GET    /users/:id(.:format)                           {:action=>"show", :controller=>"users"}
                      user PUT    /users/:id(.:format)                           {:action=>"update", :controller=>"users"}
                      user DELETE /users/:id(.:format)                           {:action=>"destroy", :controller=>"users"}
              attend_event POST   /events/:id/attend(.:format)                   {:action=>"attend", :controller=>"events"}
     remove_attendee_event POST   /events/:id/remove_attendee/:user_id(.:format) {:controller=>"events", :action=>"remove_attendee"}
                edit_event POST   /events/:id/edit(.:format)                     {:controller=>"events", :action=>"edit"}
                    events GET    /events(.:format)                              {:action=>"index", :controller=>"events"}
                    events POST   /events(.:format)                              {:action=>"create", :controller=>"events"}
                 new_event GET    /events/new(.:format)                          {:action=>"new", :controller=>"events"}
                edit_event GET    /events/:id/edit(.:format)                     {:action=>"edit", :controller=>"events"}
                     event GET    /events/:id(.:format)                          {:action=>"show", :controller=>"events"}
                     event PUT    /events/:id(.:format)                          {:action=>"update", :controller=>"events"}
                     event DELETE /events/:id(.:format)                          {:action=>"destroy", :controller=>"events"}
                  sessions POST   /sessions(.:format)                            {:action=>"create", :controller=>"sessions"}
               new_session GET    /sessions/new(.:format)                        {:action=>"new", :controller=>"sessions"}
                   session DELETE /sessions/:id(.:format)                        {:action=>"destroy", :controller=>"sessions"}
                    signup        /signup(.:format)                              {:controller=>"users", :action=>"new"}
              create_event        /create_event(.:format)                        {:controller=>"events", :action=>"new"}
                 my_events        /my_events(.:format)                           {:controller=>"events", :action=>"my_events"}
                    signin        /signin(.:format)                              {:controller=>"sessions", :action=>"new"}
                   signout        /signout(.:format)                             {:controller=>"sessions", :action=>"destroy"}
                   contact        /contact(.:format)                             {:controller=>"pages", :action=>"contact"}
                     about        /about(.:format)                               {:controller=>"pages", :action=>"about"}
                      help        /help(.:format)                                {:controller=>"pages", :action=>"help"}
                      root        /(.:format)                                    {:controller=>"pages", :action=>"home"}

我错过了什么?谢谢!

4

4 回答 4

3

对于设计用户:

/config/initializers/active_admin.rb

ActiveAdmin.setup do |config|
  config.logout_link_path = :destroy_user_session_path
  config.logout_link_method = :delete

在测试更改之前重新启动服务器。

于 2017-03-09T15:21:51.267 回答
1

我遇到了与您相同的问题。我在您的代码中看不到您的登录名和登录名?方法,但我怀疑您可能将它们放在 SessionsHelper 类或类似的类中,并且该助手像这样包含在 ApplicationController 中?

class ApplicationController < ActionController::Base
  protect_from_forgery
  include SessionsHelper
...

似乎 ActiveAdmin 也实现了这些方法,并且在 SessionsHelper 中覆盖它们会破坏它。你是在正确的道路上,几乎在那里!您可能还有另一种方法需要重命名,然后您就完成了:

登出

也重命名那个,然后你应该能够像以前一样登录和退出。祝你好运!

于 2012-04-02T20:13:24.110 回答
0

我通过在我的 SessionsHelper 中更改我的 sign_out 方法的名称来解决它。

 def sign_out_user
  current_user.update_attribute(:remember_token,
                              Adult.digest(Adult.new_remember_token))
  cookies.delete(:remember_token)
  self.current_user = nil
end

然后我不得不更改我的 SessionsController 销毁方法以匹配

def destroy
  sign_out_user   ###CHANGE HERE
  redirect_to root_url
end

此外,如果您在视图中的任何位置使用该方法。您将需要更改它,使其也与新方法名称匹配。

于 2014-08-18T02:47:27.803 回答
0
  1. 更改配置文件后,您是否“重新启动”了您的 Rails 应用程序?

  2. 你的 routes.rb 是什么样的?我想知道您是否有 2 devise_for 语句,例如

    devise_for :admin_users, ActiveAdmin::Devise.config 
    #... other routes
    devise_for :users
    

    如果是这样,请删除其中的 1 个。

  3. 确保注销链接如下所示:

    <a href="/users/sign_out" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Logout</a>
    
于 2012-03-27T00:55:56.003 回答