2013-04-24 12 views
0

所以我對rails非常陌生,我正在學習本教程並遇到以下問題。無法從Michael Hartl教程中獲得這個簡單的代碼

所以我已經建立了我的看法/助理/ application_helper.rb這樣的:

module ApplicationHelper 
# Returns the full title on a per-page basis. 
def full_title(page_title) 
    base_title = "Ruby on Rails Tutorial Sample App" 
    if page_title.empty? 
    base_title 
    else 
    "#{base_title} | #{page_title}" 
    end 
end 
end 

和我的看法/佈局/ 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 %> 
</head> 
<body> 
<%= yield %> 
</body> 
</html> 

和圖/佈局/ about.html.erb這樣的:

<% provide(:title, 'About Us') %> 
<h1>About Us</h1> 
<p> 
The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> is a project to make  a book and screencasts to teach web development with <a href="http://rubyonrails.org/">Ruby  on Rails</a>. This 
is the sample application for the tutorial. 
</p> 

現在,從我下站立,這意味着它應該顯示「安博t Us'頁面標題這樣

「Ruby on Rails教程樣例應用程序|關於我們」?

正確

但我看到的是:

「關於我們」

我曾試圖消除

<% provide(:title, 'About Us') %> 

,並把它所有的地方。

有什麼建議嗎?

非常感謝!

回答

1

應用程序幫助程序中的full_title方法僅更改您的html頁面的標題(請參閱應用程序佈局的第4行)。 h1「關於我們」將保持不變。

請注意,如果您使用的是Chrome瀏覽器,您將無法在瀏覽器頂部看到標題(請參閱Hartl's Rails教程的3.3.1部分)。

+0

AHH!我瞥見了關於使用鉻的部分。謝謝! – 2013-04-24 19:14:24

相關問題