简体   繁体   English

Rails:我安装了ActiveAdmin,我的设备链接停止工作

[英]Rails: I installed ActiveAdmin and my devise link stopped working

I have devise installed. 我已经安装好了。
And I have a link: <%= link_to "Sign up", new_user_registration_path %> 我有一个链接: <%= link_to "Sign up", new_user_registration_path %>

When I installed ActiveAdmin (for existing model User ), this link stopped working: 当我安装ActiveAdmin(对于现有模型User )时,此链接停止工作:

undefined local variable or method `new_user_registration_path'

I used git diff for routes.rb and here it is (added lines are black): 我使用git diff作为routes.rb ,这里是(添加的行是黑色的):

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

Also <%= link_to "Sign out", destroy_user_session_path, :method => :delete %> now leads to /admin/logout 另外<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>现在导致/admin/logout

How can I solve this problem? 我怎么解决这个问题?

rake routes: 耙路线:

     admin_dashboard            /admin(.:format)                       {:action=>"index", :controller=>"admin/dashboard"}
         admin_codes GET        /admin/codes(.:format)                 {:action=>"index", :controller=>"admin/codes"}
                     POST       /admin/codes(.:format)                 {:action=>"create", :controller=>"admin/codes"}
      new_admin_code GET        /admin/codes/new(.:format)             {:action=>"new", :controller=>"admin/codes"}
     edit_admin_code GET        /admin/codes/:id/edit(.:format)        {:action=>"edit", :controller=>"admin/codes"}
          admin_code GET        /admin/codes/:id(.:format)             {:action=>"show", :controller=>"admin/codes"}
                     PUT        /admin/codes/:id(.:format)             {:action=>"update", :controller=>"admin/codes"}
                     DELETE     /admin/codes/:id(.:format)             {:action=>"destroy", :controller=>"admin/codes"}
         admin_users GET        /admin/users(.:format)                 {:action=>"index", :controller=>"admin/users"}
                     POST       /admin/users(.:format)                 {:action=>"create", :controller=>"admin/users"}
      new_admin_user GET        /admin/users/new(.:format)             {:action=>"new", :controller=>"admin/users"}
     edit_admin_user GET        /admin/users/:id/edit(.:format)        {:action=>"edit", :controller=>"admin/users"}
          admin_user GET        /admin/users/:id(.:format)             {:action=>"show", :controller=>"admin/users"}
                     PUT        /admin/users/:id(.:format)             {:action=>"update", :controller=>"admin/users"}
                     DELETE     /admin/users/:id(.:format)             {:action=>"destroy", :controller=>"admin/users"}
      admin_comments GET        /admin/comments(.:format)              {:action=>"index", :controller=>"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"}
                     PUT        /admin/comments/:id(.:format)          {:action=>"update", :controller=>"admin/comments"}
                     DELETE     /admin/comments/:id(.:format)          {:action=>"destroy", :controller=>"admin/comments"}
    new_user_session GET        /admin/login(.:format)                 {:action=>"new", :controller=>"active_admin/devise/sessions"}
        user_session POST       /admin/login(.:format)                 {:action=>"create", :controller=>"active_admin/devise/sessions"}
destroy_user_session DELETE|GET /admin/logout(.:format)                {:action=>"destroy", :controller=>"active_admin/devise/sessions"}
       user_password POST       /admin/password(.:format)              {:action=>"create", :controller=>"active_admin/devise/passwords"}
   new_user_password GET        /admin/password/new(.:format)          {:action=>"new", :controller=>"active_admin/devise/passwords"}
  edit_user_password GET        /admin/password/edit(.:format)         {:action=>"edit", :controller=>"active_admin/devise/passwords"}
                     PUT        /admin/password(.:format)              {:action=>"update", :controller=>"active_admin/devise/passwords"}
                root            /                                      {:controller=>"codes", :action=>"list"}
                                /:controller(/:action(/:id(.:format)))

I checked out old revision, and routes were: 我检查了旧版本,路线是:

        new_user_session GET    /users/sign_in(.:format)               {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)               {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)              {:action=>"destroy", :controller=>"devise/sessions"}
           user_password POST   /users/password(.:format)              {:action=>"create", :controller=>"devise/passwords"}
       new_user_password GET    /users/password/new(.:format)          {:action=>"new", :controller=>"devise/passwords"}
      edit_user_password GET    /users/password/edit(.:format)         {:action=>"edit", :controller=>"devise/passwords"}
                         PUT    /users/password(.:format)              {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET    /users/cancel(.:format)                {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)                       {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)               {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)                  {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)                       {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)                       {:action=>"destroy", :controller=>"devise/registrations"}

One thing you might be missing is to declare your User model as 'registerable' to get the signup routes generated by Devise. 您可能缺少的一件事是将您的用户模型声明为“可注册”以获取由Devise生成的注册路由。

You should have something like this: 你应该有这样的东西:

class User < ActiveRecord::Base
  # Include devise modules
  devise :database_authenticatable, :registerable, ...

I ran into this problem once and this is what solved it. 我遇到过这个问题,这就是解决它的问题。

It seems that you are using the same model for both normal users and admin users. 您似乎正在为普通用户和管理员用户使用相同的模型。 ActiveAdmin requires a separate model for admins. ActiveAdmin需要一个单独的管理员模型。 Try reverting the changes made by the generator and then run this: 尝试恢复生成器所做的更改,然后运行:

rails generate active_admin:resource AdminUser
rake db:migrate

This will create an AdminUser model that will have absolutely no link with your site's users. 这将创建一个AdminUser模型,该模型绝对不会与您网站的用户建立链接。

在routes.rb中,指定devise_for:users这将恢复设计用户路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM