7

activeadmin のインストールに関する railscast の指示に従っています。インストール時に、2つのエラーが発生しました-

1)sign_inの引数の数が無効です-そのため、sign_inメソッドの名前をsign_in_userに変更し、この問題を修正しました。

それから

2) signed_in の引数の数が無効ですか? - それで、signed_in の名前を変更しましたか? is_signed_in? へのメソッド そしてそれはこの問題を修正しました。

これで、activeadmin でログアウト ボタンをクリックした場合を除き、すべてが機能しているように見えます。「正常にサインアウトしました」と表示されますが、ログアウト ボタンはまだ上隅にあり、ログアウトしませんでした。

同様の問題を抱えている人々からの提案に従って、次の2つを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

Devise ユーザーの場合:

/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

私はあなたが直面しているのと同じ問題を抱えていました。あなたのコードで、sign_insigned_in がどこにあるかわかりませんか? メソッドですが、SessionsHelper クラスなどにそれらが含まれている可能性があり、そのヘルパーが ApplicationController に含まれているのではないでしょうか?

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

ActiveAdmin もこれらのメソッドを実装しているようで、SessionsHelper でそれらをオーバーライドすると壊れます。あなたは正しい道を進んでおり、もうすぐです!名前を変更する必要があると思われる方法がもう 1 つあります。

サインアウト

それも名前を変更すると、以前と同じように、ログインとログアウトの両方ができるはずです. 幸運を!

于 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 の destroy メソッドを一致するように変更する必要がありました

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 に答える