0
votes

I've installed devise on my engine and applied the following in my application.html.erb file:

<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, :method => :delete %>
    <% else %>
        <%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
    <% end %>
</div>

It shows No route matches "/users/sign_out" and it shows error for

<%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>

Error Message NameError in Devise::Sessions#new

undefined local variable or method `destroy_user_session_path' for #<#<Class:0x007fb4da2e9618>:0x007fb4da2db9a0>

Rake Routes Result

Routes for Fd::Engine:
  users_auth_google_oauth2_callback GET      /users/auth/google_oauth2/callback(.:format)   fd/omniauth_callbacks#google_oauth2
                      fd_test_index GET      /fd/test/index(.:format)                       fd/fd/test#index
fd_omniauth_callbacks_google_oauth2 GET      /fd/omniauth_callbacks/google_oauth2(.:format) fd/fd/omniauth_callbacks#google_oauth2
                   new_user_session GET      /users/sign_in(.:format)                       devise/sessions#new
                       user_session POST     /users/sign_in(.:format)                       devise/sessions#create
               destroy_user_session DELETE   /users/sign_out(.:format)                      devise/sessions#destroy
                      user_password POST     /users/password(.:format)                      devise/passwords#create
                  new_user_password GET      /users/password/new(.:format)                  devise/passwords#new
                 edit_user_password GET      /users/password/edit(.:format)                 devise/passwords#edit
                                    PATCH    /users/password(.:format)                      devise/passwords#update
                                    PUT      /users/password(.:format)                      devise/passwords#update
           cancel_user_registration GET      /users/cancel(.:format)                        devise/registrations#cancel
                  user_registration POST     /users(.:format)                               devise/registrations#create
              new_user_registration GET      /users/sign_up(.:format)                       devise/registrations#new
             edit_user_registration GET      /users/edit(.:format)                          devise/registrations#edit
                                    PATCH    /users(.:format)                               devise/registrations#update
                                    PUT      /users(.:format)                               devise/registrations#update
                                    DELETE   /users(.:format)                               devise/registrations#destroy
            user_omniauth_authorize GET|POST /users/auth/:provider(.:format)                omniauth_callbacks#passthru {:provider=>/google_oauth2/}
             user_omniauth_callback GET|POST /users/auth/:action/callback(.:format)         omniauth_callbacks#(?-mix:google_oauth2)
                      fd_auth_index GET      /fd/auth/index(.:format)                       fd/fd/auth#index
                               root GET      /                                              fd/auth#index
      omniauth_callbacks_verify_otp GET      /omniauth_callbacks/verify_otp(.:format)       fd/omniauth_callbacks#verify_otp
  omniauth_callbacks_delete_session GET      /omniauth_callbacks/delete_session(.:format)   fd/omniauth_callbacks#sign_out

Engine routes:

Fd::Engine.routes.draw do
devise_for :users,:controllers => { :omniauth_callbacks => "omniauth_callbacks" }, :class_name => "Fd::User", module: :devise
end
2
although rake routes showing the exact path but still got the error and stange it is pointing Devise::Sessions#new class as sessions new should not be pointedRajarshi Das
Issue looks on <%= link_to "Sign out", destroy_user_session_path, :method => :delete %> line instead of what you've posted. Everything looks fine though.Surya
Try this <%= link_to user_signout_url do %>Sign out<% end %>user3620005
GhostBuster , Its not working showing same error. I installed devise in an engine so is there any Extra routes or configuration required?Elayaraja T

2 Answers

0
votes

You Integrated OmniAuth in Devise, so if user gives correct credentials devise will create session , From your question i understand session is successfully created so if you want clear session just create a action in a controller(where you start session) and give

redirect_to "/users/sign_out"

or

try

redirect_to destroy_user_session_path

I hope this will work

0
votes

Try this :

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

And make sure that you have below line in your config/initializers/devise.rb

config.sign_out_via = :get