我的_header.html.erb代码:
<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>
&#34; root_path&#34;以上应评估为&#34; /&#34;但它并没有。我正在使用michael hartl教程
的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
rake routes:
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
答案 0 :(得分:1)
您不应将/
括在引号中,因为它是一个评估为<%= link_to "sample app", root_path, id: "logo" %>
的路径助手方法。这样做:
"#{root_path}"
或者如果您喜欢使用引号,请使用<section id="education" name="education"></section>
<div id="myeducation1">
<div class="container">
<div class="row">
<div class="col-xs-6">
<p>Donec id elit non mi porta gravida at eget metus.Donec id elit non mi porta gravida at eget metus.Donec id elit non mi porta gravida at eget metus.</p>
</div>
<div class="col-xs-6">
<p>Donec id elit non mi porta gravida at eget metus.Donec id elit non mi porta gravida at eget metus.Donec id elit non mi porta gravida at eget metus.</p>
</div>
</div>
</div>
</div>
</section>
答案 1 :(得分:0)
您的root位于http://<host>/
而不是http://<host>/root_path
。 root_path
是返回url而不是路径本身的方法的名称。
答案 2 :(得分:0)
我发现了这个问题。在“/views/layout/_header.html.erb”和_footer.html.erb中,我使用“root_path”和“about_path”周围的引号而不仅仅是变量。检查所有类似的变量以确保您没有引用它们