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? %>
<p>There are not any books currently in the system.</p>
<% else %>
<p>These are the current books in our system</p>
<ul id="books">
<% @books.each do |c| %>
<li><%= link_to c.title, {:action => ''show'', :id
=> c.id} -%></li>
<% 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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 Brainard <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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? %> > <p>There are not any books currently in the system.</p> > <% else %> > <p>These are the current books in our system</p> > <ul id="books"> > <% @books.each do |c| %> > <li><%= link_to c.title, {:action => ''show'', :id => c.id} -%></li> > <% 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Assuming... - by list.rhml, you mean list.rhtml - there are a couple more lines in the view to close the </ul> 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---