Guest User

Untitled

a guest
Jul 13th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #### TABLES ####
  2. =# \d orders
  3. Table "orders"
  4. Column | Type | Modifiers
  5. ------------+-----------------------------+-----------------------------------------------------------
  6. id | integer | not null default nextval('orders_id_seq'::regclass)
  7. approved | integer |
  8. removed | integer |
  9. created_at | timestamp without time zone |
  10. updated_at | timestamp without time zone |
  11. Indexes:
  12. "orders_pkey" PRIMARY KEY, btree (id)
  13.  
  14. =# select id,approved from orders limit 3;
  15. id | approved
  16. ----+----------
  17. 1 | 1
  18. 2 | 1
  19. 3 | 1
  20.  
  21. =# \d customers
  22. Table "customers"
  23. Column | Type | Modifiers
  24. ------------+-----------------------------+-----------------------------------------------------------
  25. id | integer | not null default nextval('customers_id_seq'::regclass)
  26. name | character varying(255) |
  27. ...
  28.  
  29. =# select id from customers;
  30. id
  31. ----
  32. 1
  33. (1 row)
  34.  
  35. !!!! Only 1 record with ID = 1 !!!!
  36.  
  37. ##### DEF #####
  38. class Order < ActiveRecord::Base
  39. validates_presence_of :quote
  40.  
  41. belongs_to :approved, :class_name => "Customer", :foreign_key => "id"
  42. # has_one :remover, :class_name => "Customer", :foreign_key => "id"
  43. end
  44.  
  45. .. Somewhere in .erb ..
  46. <% @orders.each do |order| %>
  47. ...
  48. <%=h order.approved.name %>
  49. ...
  50.  
  51. #### RESULT: LOG ####
  52. ...
  53. Rendering template within layouts/orders
  54. Rendering orders/index
  55. Admin Load (0.5ms) SELECT * FROM "customers" WHERE ("customers"."id" = 1)
  56. Admin Load (0.2ms) SELECT * FROM "customers" WHERE ("customers"."id" = 2)
  57.  
  58. ActionView::TemplateError (You have a nil object when you didn't expect it!
  59.  
  60.  
  61. #### RESULT : WEB #####
  62. Showing app/views/orders/index.html.erb where line #8 raised:
  63.  
  64. You have a nil object when you didn't expect it!
  65. The error occurred while evaluating nil.nick
  66.  
  67. Extracted source (around line #8):
  68.  
  69. ...
  70. 8: <span class="approver">Approved by <%=h quote.approved.name %></span>
  71. ....
Add Comment
Please, Sign In to add comment