2012-02-04 230 views
0

我在application_helper.rb中设置了一个title实例变量,但base_title不显示在浏览器中。你能告诉我什么是错的吗?标题显示不正确

application_helper.rb

module ApplicationHelper 

    # Return a title on a per-page basis 
    def title 
    base_title = "Ruby on Rails Tutorial Sample App" 
    if @title.nil? 
     base_title 
    else 
     "#{base_title} | #{@title}" 
    end 
    end 
end 

application.html.erb

<!DOCTYPE html> 
<html> 
    <head> 
     <title><%= @title %></title> 
    <%= csrf_meta_tag %> 
     </head> 
     <body> 
      <%= yield %> 
     </body> 
</html> 

回答

1

在你没有实际调用辅助函数的观点,它只是试图输出的实例变量(@title ),不要在@前加一个函数调用:

<title><%= title %></title> 
+0

工作正常。非常感谢你。 – pdenlinger 2012-02-04 16:41:44