4

I've been struggling with something very silly here for some hours. No claptrap straight to the point. When I paste this into my posts#index page view file:

  <p><%= link_to "log out", destroy_user_session_path, :method => :delete %></p>

and click on it inside the browser, the user successfully signs out. However...

When I do this somewhere else like after the user has signed in or after the user has signed up, then the user tries to log out from a page which we can call users#index. It then only gives me this error upon clicking the log out button.

Unknown action

The action 'show' could not be found for UsersController

I've tried quite a lot of things, jquery and the jquer.uls or something are included in the application.js file,

These are my routes, and I think they're right.

Proxima::Application.routes.draw do
  devise_for :users
  resources :users
  resources :dashboard
  resources :posts
  authenticated :user do
  root :to => 'dashboard#index'
end
  resources :welcome
  devise_for :users
  resources :users
  resources :dashboard
  resources :posts
  root :to => 'welcome#index'
end

This is silly, I can't understand what's going on here, I get that silly message time after time and still no stuff happens. Then I decide to actually write down the action "show" inside the UsersController, however... When I write redirect_to welcome_path it doesn't log out, I check that by actually accessing the root url again... Any ideas?

4

4 回答 4

1

如果使用 jQuery,您需要在视图中调用“用于 jQuery 的非侵入式脚本适配器”。

<%= javascript_include_tag "jquery_ujs" %>
于 2013-10-25T16:40:12.203 回答
0

我建议您研究一下为什么您的:method => :delete链接仍然以show操作结束(响应 GET 的操作)。

在 link_to 中正确设置 javascript:method => :delete应该可以正常工作,然后转到#destroy设计会话控制器中的方法。

您还可以在此处登录/注销后尝试更改默认重定向路径:https ://github.com/plataformatec/devise/wiki/How-To:-Change-the-redirect-path-after-destroying-a-会话即退出

于 2013-03-24T10:06:27.487 回答
0

如果您误删了

//= 需要 jquery_ujs

在你的application.js

于 2014-07-23T05:29:01.870 回答
-2

所以错误是:

Unknown action

The action 'show' could not be found for UsersController

所以我进入控制器并定义了显示动作。然后我查看了一些 Devise 文档并注意到我使用了这个助手:sign_out :user. 这是临时修复:

  def show
    sign_out :user
    redirect_to welcome_path
end

但是,这只会将用户注销并重定向到welcome_path,但随后我又遇到了另一个错误:

Unknown action

The action 'show' could not be found for WelcomeController

所以我也为 Welcome 控制器定义了show动作:

class WelcomeController < ApplicationController
  def show
    render :index
  end
end

这将用户重定向回根页面。瞧!然后我点击页面上的登录名和按钮,最后看到我被要求登录到页面。我已成功注销并将用户重定向回欢迎索引 URL。万岁!:D

然而,现在奇怪的部分来了。我不明白为什么会这样。因此,当我放置此代码时,从根 URL 开始:

  <p><%= link_to "log out", destroy_user_session_path, :method => :delete %></p>

然后在我登录后单击它,它成功注销,而无需任何额外的写入控制器或类似的东西。非常顺利,不需要任何工作,但是当用户尝试从其他页面而不是 ROOT URL 注销时,它不起作用,并且我在UsersController上面收到此错误。

我不明白为什么注销请求要求在UsersController中进行显示操作。当它是销毁用户会话的 GET 请求时。我的意思是为什么我必须sign:out :user在控制器内部指定 DEVISE 应该处理的事情。请解释这种行为。

于 2013-01-20T00:03:19.520 回答