在我的rails应用程序的最新添加(使用bcrypt进行身份验证)之后,我意识到我的rails应用程序无法再路由到static_pages
控制器中的任何链接。有没有解决的办法?这是我的路线实施的问题吗?
之前:localhost:3000 / home
登录后: localhost:3000 / users / 2
登录后点击主页或任何其他链接时出错:
GET localhost:3000 / users / home 404(Not Found)
我的路线:
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
我的页眉文件位于布局中:
<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
答案 0 :(得分:0)
尝试更换您的家庭&#39;与此相关:
<%= link_to "Home", home_url %>
答案 1 :(得分:0)
在 a 标记
上使用前缀网址的斜杠<a href='/home' > Home </a>
或使用Rails选项,所有这些都应该有用......
<%= link_to 'Home', root_path %>
<%= link_to 'Home', home_path %>
<%= link_to 'Home', home_url %>
还有一件事。
如果您使用的是较新版本的Rails&lt; 4,然后建议使用获取而不是匹配。
get "home" => 'static_page#home'