"Show" action could not be found for UserController at logout | reinvent the rails

I struggled with something very stupid here for several hours. No claptrap straight to the point. When I paste this into my message file with index page #:

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

and click on it inside the browser, the user will successfully log in. But...

When I do this somewhere else, like after the user has logged in or after the user has registered, the user tries to exit the page, which we can call the user index #. Then it gives me this error when clicking the logout button.

 Unknown action The action 'show' could not be found for UsersController 

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

These are my routes, and I think they are 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 stupid, I can’t understand what is happening here, I get this stupid message time after time and still nothing is happening. Then I decide to actually write the "show" action inside the UserController, however ... When I write redirect_to welcome_path it does not log out, I verify that by actually accessing the root URL again ... Any ideas?

+4
source share
4 answers

You need to call "unobtrusive scripting script for jQuery" in your view if you are using jQuery.

 <%= javascript_include_tag "jquery_ujs" %> 
+1
source

I suggest you study why your link :method => :delete still ends in a show action (action to respond to a GET).

A properly configured javascript :method => :delete in link_to should work fine and go to the #destroy method in your development session controller.

You can also try changing the default redirection path after logging in / out here: https://github.com/plataformatec/devise/wiki/How-To:-Change-the-redirect-path-after-destroying-a-session- ie-signing-out

0
source

If you mistakenly deleted

// = jquery_ujs required

in application.js

0
source

So the error was:

 Unknown action The action 'show' could not be found for UsersController 

So, I went into the controller and defined the show action. Then I looked through some of the Devise docs and noticed this helper, which I then used: sign_out :user . This is a workaround:

  def show sign_out :user redirect_to welcome_path end 

However, this only registered the user and redirected him to the welcome_path, but then I got another error:

 Unknown action The action 'show' could not be found for WelcomeController 

So, I defined the show action for the hello controller:

 class WelcomeController < ApplicationController def show render :index end end 

This redirects the user to the root page. Voila! Then I clicked on the login button and the button on the page and saw that I was asked to enter the page. I successfully logged out and redirected the user back to the welcome index URL. Hooray !: D

However, now comes the strange part. I do not understand why this works. Therefore, from the root URL, when I put this code:

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

And then click on it after logging in, it successfully logs out without additional writing to the controllers or something like that. Very smooth and no work is required, but when a user tries to exit a different page, and not a ROOT URL, it will not work, and I get this error above using the UserController .

I do not understand why the exit request requests the show action in the UserController . When is a GET request to destroy a user session. I mean, why should I point to sign:out :user inside the controller, if that is what DEVISE should take care of. Please explain this behavior.

-2
source

All Articles