Home Can't route after user login in rails
Reply: 0

Can't route after user login in rails

user3921 Published in June 20, 2018, 7:45 am

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]

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 %>

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
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319292 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO