我已经在我的应用程序上安装了设计,并在我的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.0和design 1.4.2):

确保你的页面加载rails.js 使用这个参数:'data-method' => 'delete' 添加这个参数是个好主意::rel => 'nofollow'

其他回答

你可能没有包含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')

一切都会好起来的。

一般来说,当你得到“没有路由匹配”,但你认为你已经定义了路由,然后再次检查http verb / request方法(是否它的get, put, post, delete等)的路由。

如果您运行rake路由,那么您将看到预期的方法,您可以将其与请求日志进行比较。

我在设计中修改了这一行。

config.sign_out_via = :delete

to

config.sign_out_via = :get

它开始对我有用。

这就是我所做的(Rails 3.0和design 1.4.2):

确保你的页面加载rails.js 使用这个参数:'data-method' => 'delete' 添加这个参数是个好主意::rel => 'nofollow'

让Logout链接成为DELETE RESTful调用的能力需要一个html属性data-method = " DELETE ",使用rails code = link_to('Logout', destroy_user_session_path,:method =>: DELETE)。

然而,如果你没有安装gem jquery-ujs,或者没有在你的application.html via = javascript_include_tag "application"中调用结果的javascript,响应将作为GET请求发送,路由将失败。

如果你不想使用jquery-ujs或者找不到让它工作的方法,你有几个选择:

改变配置。Sign_out_via等于:进入设计。rb(不推荐,因为DELETE是合适的RESTful查询) 或将link_to更改为= button_to('Logout', destroy_user_session_path,:method =>:delete)。使用button_to, Rails将在进行正确的DELETE调用时完成繁重的工作。然后,如果您愿意,可以将按钮样式设置为看起来像一个链接。