ruby-on-rails – 设计注销/注销不使用Rails 4

我讨厌发布关于这个的另一个话题,因为似乎有大约十几个,但我找不到任何解决这个问题的方法.

在我的application.html.erb中,我有:

<% if user_signed_in? %>
    Logged in as <strong><%= current_user.email %></strong>.
    <%= link_to 'Settings', edit_user_registration_path %> |
    <%= link_to "Log out", destroy_user_session_path, method: :delete %>
  <% else %>
    <%= link_to "Sign up", new_user_registration_path %> |
    <%= link_to "Log in", new_user_session_path %>
  <% end %>

路线看起来像这样:

devise_for :users, 
    path_names: {sign_in: "login", sign_out: "logout"}
  resources :users
  resources :addresses

  root 'users#index'
  get 'dashboard', to: "users#dashboard"

我的本地日志看起来像这样:

started GET "/users/logout" for 127.0.0.1 at 2013-10-21 17:47:21 -0700
Processing by UsersController#show as HTML
  Parameters: {"id"=>"logout"}
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
  Rendered users/show.erb within layouts/application (1.2ms)

因此,与许多其他主题一样,它正在尝试将注销作为id传递.我有:在我的application.html.erb链接中删除,所以不是这样.

这就是我的application.js中的内容:

//= require jquery
//= require jquery_ujs
//= require_tree .

看起来很好.

有任何想法吗?我很难过……

编辑:耙路线的输出

                  Prefix Verb   URI Pattern                    Controller#Action
        new_user_session GET    /users/login(.:format)         devise/sessions#new
            user_session POST   /users/login(.:format)         devise/sessions#create
    destroy_user_session DELETE /users/logout(.:format)        devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PATCH  /users/password(.:format)      devise/passwords#update
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
       user_registration POST   /users(.:format)               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                         PATCH  /users(.:format)               devise/registrations#update
                         PUT    /users(.:format)               devise/registrations#update
                         DELETE /users(.:format)               devise/registrations#destroy
                   users GET    /users(.:format)               users#index
                         POST   /users(.:format)               users#create
                new_user GET    /users/new(.:format)           users#new
               edit_user GET    /users/:id/edit(.:format)      users#edit
                    user GET    /users/:id(.:format)           users#show
                         PATCH  /users/:id(.:format)           users#update
                         PUT    /users/:id(.:format)           users#update
                         DELETE /users/:id(.:format)           users#destroy
               addresses GET    /addresses(.:format)           addresses#index
                         POST   /addresses(.:format)           addresses#create
             new_address GET    /addresses/new(.:format)       addresses#new
            edit_address GET    /addresses/:id/edit(.:format)  addresses#edit
                 address GET    /addresses/:id(.:format)       addresses#show
                         PATCH  /addresses/:id(.:format)       addresses#update
                         PUT    /addresses/:id(.:format)       addresses#update
                         DELETE /addresses/:id(.:format)       addresses#destroy
                    root GET    /                              users#index
               dashboard GET    /dashboard(.:format)           users#dashboard
       send_im_home_text GET    /im_home(.:format)             users#im_home

最佳答案 缺少<%= javascript_include_tag:application%>在application.html.erb中,如评论中所述.

点赞