mercredi 12 octobre 2016

Raise an error on http://localhost:3000/entries/view_all

Hi guys i am currently doing chapter 13 on beginning ruby. and i am stuck at this error when accessing http://localhost:3000/entries/view_all. Even i tried to seed my database entries with values, it still doesn't work at all.

This is the expected result:

http://ift.tt/2dvAuhG

This is the error i am facing now:

Couldn't find all Entries with 'id': (all, {:include=>:Content, :order=>"created_at DESC"}) (found 0 results, but was looking for 2)

 def view_all
       #@entries = Entry.all(:order => 'created_at DESC')
       @entries = Entry.find(:all, :include => :Content, :order => "created_at DESC")
      end

This is my Entries Controller:

def view_all
   @entries = Entry.find(:all, :include => :Content, :order => "created_at DESC")
  end

This is my routes.rb:

Rails.application.routes.draw do
resources :users
resources :entries do
get :view_all, on: :collection
end
end

This is my view_all.html.erb:

<% @entries.each do |entry| %>
<h1><%= entry.Title %></h1>
<p><%= entry.Content %></p>
<p><em>Posted at <%= entry.created_at %></em></p>

<% end %>

<%= link_to 'Add New Entry', new_entry_path %>

Aucun commentaire:

Enregistrer un commentaire