我已经在我的应用程序上安装了设计,并在我的application.html.erb文件中应用了以下内容:

<div id="user_nav">
    <% if user_signed_in? %>
        Signed in as <%= current_user.email %>. This cannot be cheese?
        <%= link_to 'Sign out', destroy_user_session_path %>
    <% else %>
        <%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
    <% end %>
</div>

我运行了rake路由,确认所有路由都是有效的。

同样,在我的路线上。我有belonge_for:users和root:to => "home#index"。

当点击“签出”链接时,我得到以下路由错误:

No route matches "/users/sign_out"

知道是什么导致了这个错误吗?


当前回答

问题开始于rails 3.1…在/app/assets/javascript/中查找application.js。

如果文件不存在,创建一个文件名,我不知道为什么我的文件消失了,或者从来没有在“rails new app”....上创建

该文件是jquery....的实例

其他回答

在你的路线上使用它。rb文件:

devise_for :users do
    get '/users/sign_out' => 'devise/sessions#destroy'
end

你可能没有包含jquery_ujs javascript文件。请确保您使用的是最新版本的jquery-ujs: https://github.com/rails/jquery-ujs和最后可用的文件:

rails generate jquery:install

你应该没有更多的rails.js文件了。如果你这样做了,你可能已经过时了。 还要确保该文件在config/application.rb中加载了默认值

config.action_view.javascript_expansions[:defaults] = %w(jquery.min jquery_ujs)

(同样,这里不应该有rails.js文件)。 最后,添加在维基百科上的链接:

= link_to('Logout', destroy_user_session_path, :method => 'delete')

一切都会好起来的。

如果你使用的是HTTPS,如果你的签出链接是不安全的版本,它就会崩溃。在后端,它重定向到安全版本。这个重定向是一个GET,它导致了这个问题。

确保你的链接使用HTTPS。你可以在你的url助手中强制使用协议:“https”(确保你使用url助手而不是路径助手)。

<%= link_to "Sign out", destroy_user_session_url(protocol: "https"), method: :delete %>

页面中的“:method =>:delete”是“data-method="delete"” 所以你的页面必须有jquery_ujs.js,它会用delete方法提交链接,而不是用get方法

我认为退出的路由是一个DELETE方法。这意味着你的签出链接需要看起来像这样:

<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>

你的不包括:method =>:delete部分。另外,请注意,要实现这个功能,你还必须在布局文件(application.html.erb)中包含<%= javascript_include_tag:defaults %>。