Prev Lesson | TOC | Next Lesson

Make the topic title a link

Goal:

Your friends recommended two changes for the site:

Steps:

Let's start by removing the description. Open app/views/topics/index.html.erb and delete the line that looks like this:

<td><%= topic.description %></td>

Also delete the line that looks like this:

<th>Description</th>

If you save and try to load it in the browser you should see that the description no longer appears. Now make the title a link by editing app/views/topics/index.html.erb (again) and replace this line:

<td><%= topic.title %></td>

with this:

<td><%= link_to topic.title, topic %></td>

What Just Happened?

<td><%= topic.description %></td>

This line was getting the description using .description and just printing it out

<th>Description</th>

<th> stands for table header and everything between <th> and </th> was being printed as a table header (bold). We removed it since we removed the description and it would look funny to have the header and the wrong thing below it.

<td><%= link_to topic.title, topic %></td>

Here's another use of link_to to create a link on the page. This link_to creates a link using the text from the topic title and goes to the topic#show page.

Prev Lesson | TOC | Next Lesson