small medium large xlarge

30 Nov 2013, 05:51
Kurt Euler (6 posts)

Hi. At the end of iteration G2, when I run the command “curl –silent http://localhost:3000/products/3/who_bought.atom”, I’m not getting the neetly formatted “…<feed … </feed>” output. Instead, I’m getting jibberish like this (includes a stylesheet output, and actionpack messages, etc) :

 #container {
      box-sizing: border-box;
      width: 100%;
      padding: 0 1.5em;
actionpack (4.0.1) lib/action_controller/metal/implicit_render.rb:10:in `default_render&#39;
actionpack (4.0.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action&#39;
actionpack (4.0.1) lib/abstract_controller/base.rb:189:in `process_action&#39;
actionpack (4.0.1) lib/action_controller/metal/rendering.rb:10:in `process_action&#39;

The rails server tail shows this

Processing by ProductsController#who_bought as ATOM
  Parameters: {"id"=>"3"}
  Rendered products/who_bought.atom.builder (9.0ms)
Completed 500 Internal Server Error in 66ms

ActionView::Template::Error (undefined method `title' for nil:NilClass):
    1: atom_feed do |feed|
    2:   feed.title "Who bought #{@product.title}"
    4:   feed.updated @latest_order.try(:updated_at)
  app/views/products/who_bought.atom.builder:2:in `block in _app_views_products_who_bought_atom_builder___508106184500260856_15116720'
  app/views/products/who_bought.atom.builder:1:in `_app_views_products_who_bought_atom_builder___508106184500260856_15116720'

I can’t seem to find the issue. Any help on what might be wrong would be appreciated.

04 Dec 2013, 10:09
Ben Kwok (4 posts)

encounter the same problem. Sam. Could you kindly provide some feedback? Thanks.

05 Dec 2013, 14:12
Ben Kwok (4 posts)

Hi there. Seems I find the reason.

I compare the code provided by the book and my code, find no mispelling but notice the ‘who_bought’ method in products_controller.rb has been placed in the bottom, which is under the ‘private’ methods ‘set_product’ and ‘product_params’.

After moving the ‘who_bought’ method up before the ‘private’, stop and restart the server, and test again with the ‘curl’ command, the xml message showed. I think it’s because the ‘who_bought’ method becomes private in that way so cannot be called hence call the @product becomes nil.

Hope it helps.

06 Dec 2013, 04:21
Kurt Euler (6 posts)

Thanks Ben. I’ll see if I did the same thing.

16 Dec 2013, 10:48
Ben Kwok (4 posts)

Hi Kurt,

You may need to close the terminal that used to type curl command to see the change.

Happy coding~

  You must be logged in to comment