http://ruby.railstutorial.org/chapters/filling-in-the-layout#sec-adding_to_the_layout
我正在使用ruby 1.8.7。
当我使用他在清单5.1中提供的代码更新app / views / layouts / application.html.erb时,static_pages / home不再显示在服务器上。
原件:`
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
` 清单5.1:
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", '#', id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", '#' %></li>
<li><%= link_to "Help", '#' %></li>
<li><%= link_to "Sign in", '#' %></li>
</ul>
</nav>
</div>
</div>
</header>
<div class="container">
<%= yield %>
</div>
</body>
</html>
我甚至切换回Ruby 1.8风格的哈希:media,然后:id。
我在服务器上出错:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
运行测试时出错: 故障:
1) Static pages About page should have the h1 'About Us'
Failure/Error: visit '/static_pages/about'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:41
2) Static pages About page should have the title 'About Us'
Failure/Error: visit '/static_pages/about'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:46
3) Static pages Home page should have the base title
Failure/Error: visit '/static_pages/home'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:13
4) Static pages Home page should have the h1 'Sample App'
Failure/Error: visit '/static_pages/home'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:8
5) Static pages Home page should not have a custom page title
Failure/Error: visit '/static_pages/home'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:19
6) Static pages Contact page should have the h1 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:55
7) Static pages Contact page should have the title 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:60
8) Static pages Help page should have the h1 'Help'
Failure/Error: visit '/static_pages/help'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:27
9) Static pages Help page should have the title 'Help'
Failure/Error: visit '/static_pages/help'
ActionView::Template::Error:
compile error
/Users/admin/rails_projects/sample_app/app/views/layouts/application.html.erb:16: syntax error, unexpected tSTRING_BEG, expecting ')'
...nk_to "sample app", '#', :id "logo" );@output_buffer.safe_co...
^
# ./app/views/layouts/application.html.erb:34:in `compile'
# ./spec/requests/static_pages_spec.rb:32
Finished in 0.20551 seconds
9 examples, 9 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:40 # Static pages About page should have the h1 'About Us'
rspec ./spec/requests/static_pages_spec.rb:45 # Static pages About page should have the title 'About Us'
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title
rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App'
rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Home page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:54 # Static pages Contact page should have the h1 'Contact'
rspec ./spec/requests/static_pages_spec.rb:59 # Static pages Contact page should have the title 'Contact'
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages Help page should have the h1 'Help'
rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Help page should have the title 'Help'
如果我没有提供所有需要的信息,我很抱歉。我不确定问题是什么。
答案 0 :(得分:1)
错误与使用1.9样式哈希有关,您需要更改链接以使用1.8样式哈希,如下所示:
link_to "sample app", '#', :id => "logo"