Newbie question

I am running through this tutorial:
http://www.tutorialspoint.com/ruby-on-rails/rails-views.htm

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

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. [email protected]

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

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs