Can't route after user login in rails

acampbe222

After implementing my latest addition to my rails app (authentication using bcrypt), I realized my rails app can no longer route to any of the links in the static_pages controller. Is there a way around this? Is it a problem with my route implementation?

Before: localhost:3000/home

After Login: localhost:3000/users/2

Error that I get when I click on home or any other link after login:

GET localhost:3000/users/home 404 (Not Found)

My routes:

Rails.application.routes.draw do
      resources :user
      root  'static_pages#home'
      match '/alex' , to: 'static_pages#alex', via: 'get'
      match '/help',    to: 'static_pages#help',    via: 'get'
      match '/about',   to: 'static_pages#about',   via: 'get'
      match '/home', to:'static_pages#home', via: 'get'
      match '/contact', to:'static_pages#contact', via:'get'
      match 'users/show' , to: 'users#show', via: 'get'
      get    'login'   => 'sessions#new'
      post   'login'   => 'sessions#create'
      delete 'logout'  => 'sessions#destroy'
      get '/signup' => 'users#new'
      resources :sessions, only: [:new, :create, :destroy]
end

My Header File located in Layouts:

   <div id = "navbar">
  <ul id = "menu-nav">
   <li class = "nav-item"> <a href= "home"  >      <i class="fa fa-home">       </i>   Home </a> </li>
   <li class = "nav-item"> <a href= "help"> <i class="fa fa-music"></i>    Music </a> </li>
   <li class = "nav-item"> <a href= "about" >  <i class="fa fa-thumbs-up"></i>   Artist Discovery </a> </li>
  <li class = "nav-item"> <a href= "#"> <i class="fa fa-paper-plane">    </i>  News </a> </li>
   <li class = "nav-item"> <a href= "#"> <i class="fa fa-heart"></i>  Alex!        </a> </li>
    <% if @users == nil %>
    <li class = "nav-item"> <a href= "signup"> <i class="fa fa-heart"></i> Sign Up </a> </li>
     <li class = "nav-item"> <a href= "login"> <i class="fa fa-heart"></i> Login </a> </li>
     <% end %>
      </ul>
     </div>

Rake Routes:

  Prefix Verb   URI Pattern               Controller#Action
       root GET    /                         static_pages#home
       alex GET    /alex(.:format)           static_pages#alex
       help GET    /help(.:format)           static_pages#help
       about GET    /about(.:format)          static_pages#about
       home GET    /home(.:format)           static_pages#home
        contact GET    /contact(.:format)        static_pages#contact
       users_show GET    /users/show(.:format)     users#show
       login GET    /login(.:format)          sessions#new
          POST   /login(.:format)          sessions#create
     logout DELETE /logout(.:format)         sessions#destroy
     signup GET    /signup(.:format)         users#new
      users GET    /users(.:format)          users#index
             POST   /users(.:format)          users#create
       new_user GET    /users/new(.:format)      users#new
       edit_user GET    /users/:id/edit(.:format) users#edit
        user GET    /users/:id(.:format)      users#show
            PATCH  /users/:id(.:format)      users#update
             PUT    /users/:id(.:format)      users#update
             DELETE /users/:id(.:format)      users#destroy
           sessions POST   /sessions(.:format)       sessions#create
      new_session GET    /sessions/new(.:format)   sessions#new
      session DELETE /sessions/:id(.:format)   sessions#destroy
akz92

Try replacing your 'home' link with this:

<%= link_to "Home", home_url %>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

django - Can't login after creating user

Swift - Login with FireBase - Can't retrieve user data after login

Route user after login based on profile parameter

can't retrieve user data after the login check

Can't keep all data of user in session after login at codeigniter

Laravel: can't login user after revoke token in api testst

Can't login to new user

Can't login to Root User

Django, can't transmit user login status among pages after register and login

A specific user can't login (after connecting TV), can't figure out why

Can't redirect after login?

Can't login to django admin after successfully creating a super user with a custom user model

CodeIgniter - How to redirect user after login, to the previous attempted route

How to modify the Express route to login the user after it is created in Mongodb?

How to redirect the user to a specific route after login/register?

User can not login after registering on Laravel

Form Won't Load After User LogIn

User isn't authenticated after successful login

Can't fetch user right after login, but refresh works @nuxt-auth

Task scheduler can't show GUI of the application after logout and login (run whether user is logged on or not)

Can't Login to using root user in Kali 2.0 Sana after update

Can't get user information after login successfully in WSO2 Identity server

How can i redirect to login if user tries logout route directly

Rails 4: Can't create a session for a user through login, although the session is created when I create a new user

Django can't login user in test with UserFactory

New user can't login in Linux Mint

AD user can't login to laptop

Server didn't route to /login after serving index.html

Can't login after fresh installation