How can I debug a rails "undefined method 'url' for nil:NilClass"? -


i'm trying learn rails , i'd deeper understanding how works. , may have confusion should singular , should plural.

i have covers table in database 2 columns: url , path.

    db/schema.rb:        activerecord::schema.define(version: 20150514120143)        create_table "covers", force: :cascade |t|          t.text "url",  null: false          t.text "path"        end      ...        app/controllers/covers_controller.rb:         def index          #render text: "hello index in coverscontroller"          # can render message think routing ok          @covers = cover.all        end      ...      app/models/cover.rb      class cover < activerecord::base        validates :url, presence: true,                          length: { minimum: 3 }      end        app/views/covers/index.html.erb:        <h1>list covers</h1>        <table>        <tr>      <th>url</td>      <th>path</td>      </tr>        <% @covers.each |cover| %>      <tr>      <td><%= @cover.url %></td>      <td><%= @cover.path %></td>      </tr>      <% end %>        </table>

when navigate http://localhost:3000/covers, error undefined method `url' nil:nilclass

is trouble getting nilclass instead of cover (or covers?)

use code:

<% @covers.each |cover| %>   <tr>     <td><%= cover.url %></td>     <td><%= cover.path %></td>   </tr> <% end %> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -