Showing app/views/store/display_cart.rhtml where line #3 raised:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.size
Extracted source (around line #3):
1: <h1>Display Cart</h1>
2: <p>
3: Your cart contains <%= @items.size %> items.
4: </p>
RAILS_ROOT: /Users/bogdang/Documents/ruby/depot/public/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/views/store/display_cart.rhtml:3:in
`_run_rhtml_store_display_cart''
How can i fix this?
--
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
-~----------~----~----~----~------~----~------~--~---
> Showing app/views/store/display_cart.rhtml where line #3 raised: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.size > Extracted source (around line #3): > > 1: <h1>Display Cart</h1> > 2: <p> > 3: Your cart contains <%= @items.size %> items. > 4: </p> > RAILS_ROOT: /Users/bogdang/Documents/ruby/depot/public/../config/.. > > Application Trace | Framework Trace | Full Trace > #{RAILS_ROOT}/app/views/store/display_cart.rhtml:3:in > `_run_rhtml_store_display_cart'' > > How can i fix this?Well, one way would be to ensure that @items was always an array before you get to your view, but if you just want to deal with it in the view do: Your cart contains <%= @items.nil? ? "no items" : pluralize(@items.size, "item")) %>. WHich would result in: no items 1 item 2 items depending on if there are no, 1, or 2 (or more) items in the cart. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the help, but I all ready fix it. Now it working it shoud be, I have a private method and that''s why, and I had to add the display_cart method above the private method which I have. Regards Dan, Philip Hallstrom wrote:>> 4: </p> >> RAILS_ROOT: /Users/bogdang/Documents/ruby/depot/public/../config/.. >> >> Application Trace | Framework Trace | Full Trace >> #{RAILS_ROOT}/app/views/store/display_cart.rhtml:3:in >> `_run_rhtml_store_display_cart'' >> >> How can i fix this? > > Well, one way would be to ensure that @items was always an array before > you get to your view, but if you just want to deal with it in the view > do: > > Your cart contains <%= @items.nil? ? "no items" : pluralize(@items.size, > "item")) %>. > > WHich would result in: > > no items > 1 item > 2 items > > depending on if there are no, 1, or 2 (or more) items in the cart. > > -philip-- 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 -~----------~----~----~----~------~----~------~--~---