我陷入了奇怪的境地。我在SO论坛上看到了很多答案,但没有解决我的问题。我正在开发一个ruby on rails应用程序。我已创建注册并成功登录。但我的签出不起作用。 这是我在应用程序标题
中注销的视图<div class="header">
<%= image_tag "header.png", :class => "headerimg" %>
<% unless current_user.blank? %>
<div id="menu_container" >
<ul class="sf-menu" id="nav" >
<li style="margin-left:10%">
<%= link_to current_user.First_Name, {} %>
</li>
<li>
<%= link_to "notif", {} %>
</li>
<li id="logout" style="margin-left:55%;">
<%= link_to "Log out", signout_path, method: "delete" %>
</li>
</ul>
</div>
<% end %>
</div>
我的会话控制器是
def destroy
sign_out
redirect_to root_url
end
我的会员帮助退出是
def sign_out
cookies.delete(:remember_token)
self.current_user = nil
end
我的佣金路线的结果是:
Helper HTTP Verb Path Controller#Action
Path / Url
users_path GET /users(.:format) users#index
POST /users(.:format) users#create
new_user_path GET /users/new(.:format) users#new
edit_user_path GET /users/:id/edit(.:format) users#edit
user_path GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions_path POST /sessions(.:format) sessions#create
new_session_path GET /sessions/new(.:format) sessions#new
session_path DELETE /sessions/:id(.:format) sessions#destroy
root_path GET / static_pages#home
signup_path GET /signup(.:format) users#new
signin_path GET /signin(.:format) sessions#new
signout_path DELETE /signout(.:format) sessions#destroy
default_path GET /default(.:format) static_pages#default
我无法弄清楚我在做什么。我跟随Michael Hartl。 Plz指出了我正确的方向。
由于
修改 这是我得到的错误
No route matches [GET] "/signout"
这里有完整的错误痕迹
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
答案 0 :(得分:2)
您的link_to
写得正确,但您可以看到它发出了GET
请求。由于方法DELETE
是使用javascript强制执行的,因此您很可能不会包含application.js
,或者您的javascript中存在错误,导致无法正确解析它。
因此,请确保在您的应用程序布局(views/layouts/application.html.erb
)
<%= javascript_include_tag "application" %>
或者检查浏览器javascript控制台中的错误。