【问题标题】:Cannot get this simple code to work from the Michael Hartl Tutorial无法从 Michael Hartl 教程中获取这个简单的代码
【发布时间】:2013-05-08 23:34:04
【问题描述】:

所以我对 Rails 很陌生,我正在学习本教程并遇到以下问题。

所以我已经像这样设置了我的视图/helpers/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>

现在,根据我的理解,这意味着它应该像这样显示“关于我们”的页面标题

“Ruby on Rails 教程示例应用程序 | 关于我们”

正确吗?

但是我看到的只是:

“关于我们”

我试过删除

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

并将其放置在所有地方。

有什么建议吗?

非常感谢!

【问题讨论】:

    标签: ruby-on-rails ruby html railstutorial.org


    【解决方案1】:

    应用程序助手中的 full_title 方法只会改变你的 html 页面的 title(参见应用程序布局的第 4 行)。 h1“关于我们”将保持静态。

    请注意,如果您使用的是 Chrome 浏览器,您将无法在浏览器顶部看到标题(请参阅 Hartl 的 Rails 教程的 3.3.1 部分)。

    【讨论】:

    • 啊!我对使用 chrome 的部分很感兴趣。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-09
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多