Guest User

Untitled

a guest
Jul 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #do I have the stupids today, or is this just a bit weird?
  2.  
  3. class Categorization < ActiveRecord::Base
  4.  
  5. belongs_to :category
  6. belongs_to :categorized_content, :polymorphic => true
  7. end
  8.  
  9. ?> cat
  10. => #<Category id: 528, category_type_id: 1, parent_id: 219, name: "Brolgas", created_at: "2010-02-04 01:49:53", updated_at: "2010-02-04 01:49:53">
  11. >> cat.categorizations
  12. => [#<Categorization id: 2, category_id: 528, categorized_content_id: 2, categorized_content_type: "Dataset", created_at: "2010-02-04 02:39:20", updated_at: "2010-02-04 02:39:20">]
  13. >> cat.categorizations.first
  14. => #<Categorization id: 2, category_id: 528, categorized_content_id: 2, categorized_content_type: "Dataset", created_at: "2010-02-04 02:39:20", updated_at: "2010-02-04 02:39:20">
  15. >> cat.categorizations.first.category
  16. NoMethodError: You have a nil object when you didn't expect it!
  17. You might have expected an instance of Array.
  18. The error occurred while evaluating nil.include?
  19. from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?'
  20. from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods'
  21. from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:71:in `each'
  22. from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods'
  23. from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:242:in `method_missing'
  24. from (irb):28
  25. >>
Add Comment
Please, Sign In to add comment