Guest User

Untitled

a guest
May 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. # stick this method in project.rb
  2. def self.list_of_person_ids_who_are_participants_and_belong_to_an_activity(project_id)
  3. joins = "JOIN activities ON activities.project_id = projects.id "
  4. joins << "JOIN activity_executions ON activity_executions.activity_id = activities.id"
  5.  
  6. conditions = ["projects.id = ? ", project_id]
  7.  
  8. find( :all,
  9. :select => 'activity_executions.person_id',
  10. :conditions => conditions,
  11. :joins => joins)
  12. end
  13.  
  14. # go to ruby script/console and perform following operation
  15. >> Project.list_of_person_ids_who_are_participants_and_belong_to_an_activity(1)
  16.  
  17. # I get following error from auto_escape
  18. >> Project.list_of_person_ids_who_are_participants_and_belong_to_an_activity(1)
  19. Project Load (0.000929) SELECT activity_executions.person_id FROM `projects` JOIN activities ON activities.project_id = projects.id JOIN activity_executions ON activity_executions.activity_id = activities.id WHERE (projects.id = 1 )
  20. Project Columns (0.003555) SHOW FIELDS FROM `projects`
  21. NoMethodError: You have a nil object when you didn't expect it!
  22. The error occurred while evaluating nil.text?
  23. from /Users/nkumar/work/community_service/vendor/plugins/auto_escape/lib/auto_escape.rb:57:in `after_find'
  24. from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/set.rb:231:in `delete_if'
  25. from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/set.rb:231:in `delete_if'
  26. from /Users/nkumar/work/community_service/vendor/plugins/auto_escape/lib/auto_escape.rb:57:in `after_find'
  27. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:301:in `send'
  28. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/callbacks.rb:301:in `callback'
  29. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1446:in `send'
  30. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1446:in `instantiate'
  31. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:582:in `find_by_sql'
  32. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:582:in `collect!'
  33. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:582:in `find_by_sql'
  34. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1341:in `find_every'
  35. from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:536:in `find'
  36. from /Users/nkumar/work/community_service/app/models/project.rb:321:in `list_of_person_ids_who_are_participants_and_belong_to_an_activity'
  37. from (irb):8
Add Comment
Please, Sign In to add comment