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>
:media と :id のハッシュを Ruby 1.8 スタイルに戻しました。
サーバーで発生するエラー:
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'
必要なすべての情報を提供していない場合は申し訳ありません。何が問題なのかよくわかりません。