To Examples

BlogPostSite Example -- Corrected Errors

Source code files with errors in BoxModel/app/views/blogs: index, show, new, edit,and, _form.html.erb.

Corrections are shown in red.

Find the errors in these views:

---- BlogPostSite/app/views/blogs/index.html.erb -----------------

<h1>Listing Blogs</h1>

<table>
  <thead>
  <tr>
    <th>Screen name</th>
    <th>Message</th>
    <th colspan="3"></th>
  </tr>
  </thead>

  <tbody>
  <% @blogs.each do |blog| %>   <-- Reverse do and |blog|
  <tr>
    <td><%= blog.screen_name %></td>
    <td><%= blog.message %></td>
    <td><%= link_to 'Show', blog %></td>
    <td><%= link_to 'Edit', edit_blog_path(blog) %></td>
    <td><%= link_to 'Destroy', blog, method: :delete, 
         data: { confirm: 'Are you sure?' } %></td> <-- Insert %>
  </tr>
  <% end %>   <-- Remove =
  </tbody>  <-- Insert </tbody>
</table>

<br>

<%= link_to 'New Blog', new_blog_path %>  <-- Replace blogs_path

---- BlogPostSite/app/views/blogs/show.html.erb -----------------

<p id="notice"><%= notice %></p>   <-- Replace ' with "

<p>
  <strong>Screen name:</strong>
  <%= @blog.screen_name %>
</p>

<p>
<strong>Date and Time:</strong>
  <!-- Reference site for Time method strftime:
       http://apidock.com/ruby/DateTime/strftime -->
  <%= @blog.created_at.strftime("%-m/%-d/%y %l:%M:%S %p") %> <-- Insert =
</p>

<p>
  <strong>Message:</strong>
  <%= @blog.message %>  <-- Insert @
</p>    <-- Insert /

<%= link_to 'Edit', edit_blog_path(@blog) %> |
<%= link_to 'Back', blogs_path %> <-- Remove (@blog) from blogs_path(@blog)

---- BlogPostSite/app/views/blogs/new.html.erb -----------------

<h1>New Blog</h1>   <-- Replace h2 with h1

<%= render 'form' %>   <-- Replace _form with form

<%= link_to 'Back', blogs_path %>

---- BlogPostSite/app/views/blogs/edit.html.erb -----------------

<h1>Editing Blog</h1>

<%= render 'form' %>

<%= link_to 'Show', @blog %> |     <!-- Insert @
<%= link_to 'Back', blogs_path %>  <!-- Insert =

---- BlogPostSite/app/views/blogs/_form.html.erb -----------------

<%= form_for(@blog) |f| %>    <-- Insert =
  <% if @blog.errors.any? %>
  <div id="error_explanation">
  <h2><%= pluralize(@blog.errors.count, "error") %> 
          prohibited this blog from being saved:</h2>

  <ul>
    <% @blog.errors.full_messages.each do |message| %>
      <li><%= message %></li>
    <% end %>
  </ul>
  </div>
<% end %>

<div class="field">
  <%= f.label :screen_name %><br>  <-- Insert _
  <%= f.text_field :screen_name %> <-- Insert :
</div>
<div class="field">
  <%= f.label :message %><br>
  <%= f.text_area :message %>  <-- Insert _
</div>
<div class="actions">
  <%= f.submit >
</div>
<% end %>   <-- Replace <%= with <%

---------------------------------------------------------------