0

http://ruby.railstutorial.org/chapters/filling-in-the-layout#sec-adding_to_the_layout

我正在使用红宝石 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'

如果我没有提供所有需要的信息,我很抱歉。我不确定问题是什么。

4

1 回答 1

1

该错误与使用 1.9 样式哈希有关,您需要将链接更改为使用 1.8 样式哈希,如下所示:

link_to "sample app", '#', :id => "logo"
于 2013-01-30T01:14:22.003 回答