开发者

Web page written using Ruby on Rails won't display changes in title text

开发者 https://www.devze.com 2023-02-13 00:36 出处:网络
I am new to Ruby on Rails and working through a tutorial. One of the lessons consists of test that ensures all pages have the correct title. However, even when I change the title using HTML in the vie

I am new to Ruby on Rails and working through a tutorial. One of the lessons consists of test that ensures all pages have the correct title. However, even when I change the title using HTML in the views directory, the title does not actually change and instead displays the name of the app itself for the title. Why might this be? How could I remedy this?

Here is my HTML in the View folder:

<!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>

Here is my test:

it "should have the right title" do
      get 'home'
      response.should have_selector("title",
                        :content开发者_如何学Python => "Ruby on Rails Tutorial Sample App | Home")
    end


You likely have a file named app/views/layouts/application.html.erb

This layout view has its own HTML structure, including a <%= yield %> statement.

The view is stuffing your HTML on the view page inside of that yield statement. So both the browser and your test are looking at the first <html><head><title> that it finds.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号