使用Ruby on Rails编写的网页不会显示标题文本的更改

Spe*_*cer 1 html ruby-on-rails title

我是Ruby on Rails的新手并且正在完成一个教程.其中一个课程包括测试,确保所有页面都具有正确的标题.但是,即使我在views目录中使用HTML更改标题,标题也不会实际更改,而是显示标题的应用程序本身的名称.为什么会这样?我怎么能补救这个?

这是我在View文件夹中的HTML:

<!DOCTYPE html>
<html>
  <head>
    <title>Ruby on Rails Tutorial Sample App | Home</title>
  </head>
  <body>
    <h1>Sample App</h1>
    <p>
      This is the home page for the
      <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
      sample application.
    </p>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的测试:

it "should have the right title" do
      get 'home'
      response.should have_selector("title",
                        :content => "Ruby on Rails Tutorial Sample App | Home")
    end
Run Code Online (Sandbox Code Playgroud)

Jes*_*ott 6

您可能有一个名为的文件 app/views/layouts/application.html.erb

此布局视图具有自己的HTML结构,包括<%= yield %>语句.

该视图将HTML填充在该yield语句的视图页面上.因此浏览器和测试都会查看<html><head><title>它找到的第一个.