我按照railscast的说明安装activeadmin。安装后,我遇到了两个错误 -
1)sign_in的args数量无效 - 所以我将sign_in方法重命名为sign_in_user并解决了这个问题。
然后
2)signed_in的args数无效? - 所以我重命名了我的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"}
我错过了什么?谢谢!
答案 0 :(得分:1)
我遇到了你面临的同样问题。我无法在您的代码中看到您使用 sign_in 和 signed_in?方法,但我怀疑您可能在SessionsHelper类或类似方法中使用它们,并且该帮助程序ApplicationController中包含这样的内容吗?
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
...
似乎ActiveAdmin也实现了这些方法,并且在SessionsHelper中覆盖它们会破坏它们。你走在正确的道路上,几乎就在那里!还有一种方法可能需要重命名,然后就完成了:
<强> SIGN_OUT 强>
重命名那个,那么你应该能够像以前一样登录和退出。祝你好运!
答案 1 :(得分:1)
对于Devise用户:
在/config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
config.logout_link_path = :destroy_user_session_path
config.logout_link_method = :delete
在测试更改之前RESTART SERVER 。
答案 2 :(得分:0)
更改配置文件后,您是否“重启”了rails应用程序?
你的路线是什么样的.rb看起来像什么?我想知道你是否有2个devise_for语句,例如
devise_for :admin_users, ActiveAdmin::Devise.config
#... other routes
devise_for :users
如果是这样,请删除其中一个。
确保注销链接如下所示:
<a href="/users/sign_out" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Logout</a>
答案 3 :(得分: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 destroy方法以匹配
def destroy
sign_out_user ###CHANGE HERE
redirect_to root_url
end
此外,如果您在视图中的任何位置使用该方法。您需要对其进行更改,使其与新方法名称匹配。