Rails 3 - Can Active_admin use an existing user model?

前端 未结 4 1014
闹比i
闹比i 2020-12-22 23:05

Can Active Admin use my current Devise user model? It already has a column named admin, and if it\'s true, I\'d l

4条回答
  •  离开以前
    2020-12-22 23:55

    As stated earlier, you will need to update your config/initializers/active_admin.rb to reflect the correct auth method.

    Additionally, however, you will want to update the following settings as well:

    # This setting changes the method which Active Admin calls
    # to return the currently logged in user.
    config.current_user_method = :current_admin_user
    

    to

    config.current_user_method = :current_user
    

    and

    # This setting changes the path where the link points to. If it's
    # a string, the strings is used as the path. If it's a Symbol, we
    # will call the method to return the path.
    #
    # Default:
    config.logout_link_path = :destroy_admin_user_session_path
    

    to

    config.logout_link_path = :destroy_user_session_path
    

    Of course, you don't HAVE to update these (or the method mentioned in the post), and just over-ride the methods elsewhere, but this seems to be the easiest / cleanest approach. You will obviously need to substitute "user" in each setting (current_USER) with the name of the model using devise authentication.

    I would also recommend updating the following setting as well while you are in there:

    # This setting changes the http method used when rendering the
    # link. For example :get, :delete, :put, etc..
    #
    # Default:
    config.logout_link_method = :get
    

    to

    config.logout_link_method = :delete
    

    This last change is required if the default HTTP method used by your devise config is set to :delete, which it is unless you changed it. It matters that they are now synced because if you follow these instructions, you will be using destroy_user_session_path which is a path already defined by devise. Otherwise you will get a message stating that [GET] /users/sign_out route does not exist.

提交回复
热议问题