我的代碼_header.html.erb:沒有路由匹配GET root_path
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<%= link_to "sample app", 'root_path', id: "logo" %>
<nav>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", 'root_path' %></li>
<li><%= link_to "Help", 'help_path' %></li>
<li><%= link_to "Log in", '#' %></li>
</ul>
</nav>
</div>
</header>
的 「root_path」 上面應該被評估爲 「/」,但事實並非如此。我現在用的邁克爾·哈特爾教程
的routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
get '/signup', to: 'users#new'
post '/signup', to: 'users#create'
resources :users
end
耙路線:
Richard:sample_app richard$ rake routes
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#home
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
signup GET /signup(.:format) users#new
POST /signup(.:format) users#create
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
問題是我使用「root_path」作爲應該評估的變量爲「/」,但它不 – Richard
請發表您的視圖 –