M Hartl's Ruby on Rails Tutorial Chapter 5 Custom Title on Home Page

M Hartl's Ruby on Rails Tutorial Chapter 5 custom title on home page

What about this?

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

http://ruby.railstutorial.org/chapters/rails-flavored-ruby#code-title_helper

Just call the method inside your view.
So it should be something like
<title><%= full_title(yield(:title)) %></title>
as he says.

expected css title Hartl's Tutorial Chapter 5 Exercises

The problem is because your links in layouts/footer and layouts/header don't go anywhere. They're clickable by the spec, but they just go to # rather than their proper page. If you correct these links then the spec will work.

In app/views/layouts/_footer.html.erb:

<li><%= link_to "About",   '/about' %></li>
<li><%= link_to "Contact", '/contact' %></li>

In app/views/layouts/_header.html.erb:

 <li><%= link_to "Home",    '/' %></li>
<li><%= link_to "Help", '/help' %></li>

Hartl's railstutorial.org Chapter 5, exercise 2

I'm working on the same book, and am at the same chapter as you! I see the following:

--- expected
+++ actual
@@ -1 +1 @@
-"Help | Ruby on Rails Tutorial Sample App"
+"Ruby on Rails Tutorial Sample App"

Rearranged:

--- expected
-"Help | Ruby on Rails Tutorial Sample App"

+++ actual
+"Ruby on Rails Tutorial Sample App"

The test expected "Help | Ruby on Rails Tutorial Sample App", but actually got "Ruby on Rails Tutorial Sample App".

If you look at the help page in a browser, what shows up in the title bar? The help.html.erb looks right to me.

I also have the following for my app/helpers/application_helper.rb, is a little different from yours:

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
page_title + " | " + base_title
end
end
end

Michael Hartl Tutorial Chapter 5 | ArgumentError in Static_pages#home

Give this a read https://github.com/rails/rails/issues/660

But the end solution I think to solve your problem is to move your project to the drive where Rails is installed to so C:\

Rails Tutorial by Michael Hartl - Chapter 5.3

Make sure the following files are filled in exactly.

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
page_title + " | " + base_title
end
end
end

contact.html.erb:

<% provide(:title, 'Contact') %>
<h1>Contact</h1>
<p>
Contact the Ruby on Rails Tutorial about the sample app at the
<a href="http://www.railstutorial.org/#contact">contact page</a>.
</p>

about.html.erb:

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

help.html.erb:

<% provide(:title, "Help") %>
<h1>Help</h1>
<p>
Get help on the Ruby on Rails Tutorial at the
<a href="http://www.railstutorial.org/#help">Rails Tutorial help section</a>.
To get help on this sample app, see the
<a href="http://www.railstutorial.org/book"><em>Ruby on Rails Tutorial</em>
book</a>.
</p>

Then to fix the first error, (as also suggested by @0r4cl3) in the command line run: rake db:migrate.

If all the above steps still do not fix all your errors, check the following file:

application.html.erb:

<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>

Hartl Rails Tutorial - Chapter 3

Please check your code on the second line of this code block.

  test "should get contact" do
# get static_pages_about_url # This is wrong correct it to as below
get static_pages_contact_url
assert_response :success
assert_select "title", "Contact | #{@base_title}"
end

You have given a test case to check the contact page title on the about url which obviously will fail the test.

You should be testing for contact page title on the contact url like above.

Make the change and you should get going!

Also a word of motivation, just keep going even if things don't make sense right now cause later they will. Cheers :)

expected css title with text Ruby on Rails Tutorial Sample App | Sign Up to return something

Your test is expecting "Sign up", you're passing "Sign Up". Note the difference in capitalization on the word "up".



Related Topics



Leave a reply



Submit