2012-12-31 34 views
1

我得到錯誤,當我測試誤差的我的應用程序日誌中::的ActionView ::模板錯誤:未定義的方法`到」

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> 

任何一個可以請幫助爲什麼我收到這個未定義方法的錯誤,以及如何擺脫它?

回答

0

也許你可能在_header文件中的錯字,怎麼把每個錯誤都有它,再次檢查_header文件,如果是這樣的話同樣的錯誤,你應該得到當u運行軌道服務器並嘗試訪問

的頁面,並顯示我們您_header代碼,如果可能的

HTH

+0

是的,我要替換的鏈接與在的link_to頭感謝提示! –

+0

NP,很高興幫助:) – sameera207

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 
+1

我想你忽略了逗號。 –

+0

乾杯,壞的複製粘貼作業;) – simonmorley

+0

不解決同樣的錯誤!和其在書邁克爾哈特爾(我選擇的方法)。在要求我檢查10次代碼和書籍sincerely.Happy新的一年!享受 –

相關問題