# Newbie question

**URL:** <https://www.ruby-forum.com/t/newbie-question/127304>\
**Category:** Rails\
**Created:** [January 28, 2008, 2:45am UTC](https://www.ruby-forum.com/t/newbie-question/127304 "2008-01-28T02:45:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [January 28, 2008, 2:45am UTC](https://www.ruby-forum.com/t/newbie-question/127304/1 "2008-01-28T02:45:33Z")

</div>

I am running through this tutorial:

> **[Ruby on Rails - Views](http://www.tutorialspoint.com/ruby-on-rails/rails-views.htm)**
>
> Ruby on Rails Views - A Rails View is an ERb program that shares data with controllers through mutually accessible variables.

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 =\> c.id} -%\>
\<% end %\>

Here is list in the controller:

def list  
@books = Book.find(:all)  
end  
Here is the model  
class Book \< ActiveRecord::Base  
belongs\_to :subject  
validates\_presence\_of :title  
validates\_numericality\_of :price, :message=\>“Error Message”

end

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

Thanks  
Chris

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [January 28, 2008, 6:38am UTC](https://www.ruby-forum.com/t/newbie-question/127304/2 "2008-01-28T06:38:05Z")

</div>

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  
end

On Jan 27, 8:45 pm, Chris B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [January 28, 2008, 6:44am UTC](https://www.ruby-forum.com/t/newbie-question/127304/3 "2008-01-28T06:44:28Z")

</div>

Assuming…

- 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.  
Like…

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