Newbie question

I am running through this tutorial:

I have created the forms and the input form is working to create books
and they are in the database but when I go to list.rhml it keeps telling
me there are no books. Here is the code:

<% if @books.blank? %>

There are not any books currently in the system.

<% else %>

These are the current books in our system

    <% @books.each do |c| %>
  • <%= link_to c.title, {:action => 'show', :id =>} -%>
  • <% end %>

    Here is list in the controller:

    def list
    @books = Book.find(:all)
    Here is the model
    class Book < ActiveRecord::Base
    belongs_to :subject
    validates_presence_of :title
    validates_numericality_of :price, :message=>“Error Message”


    If you can give me any insight that would be great!


Hmmm…I don’t see the error in the code. What happens when you add
this debug statement to the controller? What does it print?

def list
@books = Book.find(:all)
p @books

On Jan 27, 8:45 pm, Chris B. [email protected]


  • by list.rhml, you mean list.rhtml
  • there are a couple more lines in the view to close the
and end
the else block
  • you’ve verified that the books are in the development database
    … something doesn’t add up.
  • To find the bug, the first thing I’d do would be to put a raise or a
    breakpoint in the controller action to make sure it’s being called.

    def list
    raise “yes, ‘list’ is being called.”
    @books = Book.find(:all)