1

エラーのアプリログをテストするとエラーが発生します

1) Static pages Home page should have the h1 'Sample App'
     Failure/Error: visit root_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xa674fa8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:5:in `block (3 levels) in <top (required)>'

  2) Static pages Home page should have the base title
     Failure/Error: visit root_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xa8eaf58>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

  3) Static pages Home page should not have a custom page title
     Failure/Error: visit root_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xb63d804>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>'

  4) Static pages Help page should have the h1 'Help'
     Failure/Error: visit help_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xa65f284>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'

  5) Static pages Help page should have the title 'Help'
     Failure/Error: visit help_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xa56dcb8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'

  6) Static pages About page should have the h1 'About'
     Failure/Error: visit about_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xb839450>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:29:in `block (3 levels) in <top (required)>'

  7) Static pages About page should have the title 'About Us'
     Failure/Error: visit about_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xa65a464>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:33:in `block (3 levels) in <top (required)>'

  8) Static pages Contact page should have the h1 'Contact'
     Failure/Error: visit contact_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xa56d808>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:40:in `block (3 levels) in <top (required)>'

  9) Static pages Contact page should have the title 'Contact'
     Failure/Error: visit contact_path
     ActionView::Template::Error:
       undefined method `to' for #<#<Class:0xa66470c>:0xb835be8>
     # ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___446387253_86947970'
     # ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb__887388821_90453380'
     # ./spec/requests/static_pages_spec.rb:44:in `block (3 levels) in <top (required)>'

Finished in 0.45434 seconds
9 examples, 9 failures

Failed examples:

私のroutes.rbファイルは

Sample::Application.routes.draw do
 root to: 'static_pages#home'

match '/help', to: 'static_pages#help'
match '/contact', to: 'static_pages#contact'
match '/about' , to: 'static_pages#about'
  end

私の_header.html.erbコードは

<header class="navbar navbar-fixed-top">
<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>

そしてapplication.html.erbコードは

<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
</html>

なぜ私がこの未定義のメソッドエラーを取得しているのか、そしてそれを取り除く方法を誰かが助けてくれますか?

4

2 に答える 2

1

これを試して:

Sample::Application.routes.draw do
   match '/help' => 'static_pages#help'
   match '/contact' => 'static_pages#contact'
   match '/about' => 'static_pages#about'
   root :to => 'static_pages#home'
end
于 2012-12-31T10:56:43.793 に答える
0

_header ファイルにタイプミスがある可能性があります。すべてのエラーにタイプミスがあるため、_header ファイルをもう一度確認してください。この場合は、Rails サーバーを実行してページにアクセスしようとしたときに同じエラーが発生するはずです。

于 2012-12-31T11:25:22.990 に答える