Hello: I''m new to rails (and ruby for that matter) and I''m us following the tutorial in the Pragmatic Programmer Agile Web Development with Rails book. In chapter 9, Iteration D1: Capturing an order, I''ve added the code to handle entry errors: <%= error_messages_for(:order) %> to the top of the checkout.rhtml file. Now when I press the checkout link I get the following: NoMethodError in Store#checkout Showing app/views/store/checkout.rhtml where line #2 raised: You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occured while evaluating nil.errors Extracted source (around line #2): 1: <% @page_title = "Checkout" -%> 2: <%= error_messages_for(:order) %> 3: <%= render_component(:action => "display_cart", 4: :params => { :context => :checkout }) %> 5: Please enter your details below Without that line the page loads fine. If i press the checkout button with no entry in any field the page displays fields highlighted red thanks to the scaffold.css file being linked in. At this point if I add that line of code back in and then press reload the error messages are shown correctly. It''s as if the order object doesn''t exist until the button is pressed and the validation entries are generated. I''ve tried this line of code several different ways because I noticed that earlier in the book a similar line is added to the partial form in the admin view: <%= error_messages_for ''product'' %> So I tried each of the following with the same result: <%= error_messages_for ''order'' %> <%= error_messages_for "order" %> <%= error_messages_for (''order'') %> <%= error_messages_for ("order") %> I tend to think that I just missed something but I guess it''s possible there''s a problem with the tutorial. Has anyone got any thoughts on this? I''ve searched through the wiki and I''ve found nothing so far. Thanks: Rob _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
matthew clark
2006-Jan-16 23:26 UTC
[Rails] You hava a nil object when you didn''t expect it!
What does your controller look like? On 1/15/06, Robert Squire <rjsquire@ebi-online.com> wrote:> > Hello: > I''m new to rails (and ruby for that matter) and I''m us following the > tutorial in the Pragmatic > Programmer Agile Web Development with Rails book. > In chapter 9, Iteration D1: Capturing an order, I''ve added the code to > handle entry errors: > > <%= error_messages_for(:order) %> > > to the top of the checkout.rhtml file. Now when I press the checkout link > I get the following: > NoMethodError in Store#checkout > > Showing *app/views/store/checkout.rhtml* where line *#2* raised: > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occured while evaluating nil.errors > > Extracted source (around line *#2*): > > 1: <% @page_title = "Checkout" -%> > 2: <%= error_messages_for(:order) %> > 3: <%= render_component(:action => "display_cart", > 4: :params => { :context => :checkout }) %> > 5: <h3>Please enter your details below</h3> > > Without that line the page loads fine. If i press the checkout button with > no entry in any field the page displays fields highlighted red thanks to > the scaffold.css file being linked in. At this point if I add that line of > code back in and then press reload the error messages are shown correctly. > It''s as if the order object doesn''t exist until the button is pressed and > the validation entries are generated. > > I''ve tried this line of code several different ways because I noticed that > earlier in the book a similar line is added to the partial form in the > admin view: > > <%= error_messages_for ''product'' %> > > So I tried each of the following with the same result: > > <%= error_messages_for ''order'' %> > <%= error_messages_for "order" %> > <%= error_messages_for (''order'') %> > <%= error_messages_for ("order") %> > > I tend to think that I just missed something but I guess it''s possible there''s > a problem with the tutorial. > > Has anyone got any thoughts on this? I''ve searched through the wiki and > I''ve found nothing so far. > > > Thanks: > > Rob > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060116/2ebcf193/attachment.html