Che
Che

Reputation: 122

displaying info from db with rails doesn't work

I'm actually working on a simple rails app. I generated a Rails g scaffold Course.

Picture of folders generated by the scaffold

Now i want to display all the courses that i create, with a title, a picture and a short description. here is the code to do it

<p id="notice"><%= notice %></p>
<h1>Courses</h1>
<div class="row">
<% @courses.each do |course| %>
      <div class="col-sm-6 col-md-4 col-lg-3">
        <div class="thumbnail">
          <td><%= link_to 'Show', course %></td>
          <td><%= link_to 'Edit', edit_course_path(course) %></td>
          <td><%= link_to 'Destroy', course, method: :delete, data: { confirm: 'Are you sure?' } %></td>
          <%= image_tag( course.image, width: 250, height: 250) %>
          <div class="caption">
            <h3><% course.title %></h3>
            <p><% course.description %></p>
            <%= link_to 'that course', course_path(course), class:"btn btn-default"%>
          </div>
        </div>
      </div>
    <% end %>
    </div>
<%= link_to 'New Course', new_course_path %>

With this, the picture is displayed, but not the title and the description neither Html is made by rails to make the title and the description, but it stay empty. Source code

I suppose that i made a mistake somewhere but i can't figure it out.

ps: I checked with the rails console, the title and the description exist in my database

Thx for your help

Upvotes: 1

Views: 37

Answers (1)

Ursus
Ursus

Reputation: 30056

This

<h3><% course.title %></h3>
<p><% course.description %></p>

Should be

<h3><%= course.title %></h3>
<p><%= course.description %></p>

Upvotes: 1

Related Questions