Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. def self.post_template
  2. posts = Post.all
  3. result = []
  4.  
  5. posts.each do |post|
  6. single_post = {}
  7. single_post['comment_title'] = post.comment.title
  8. single_post['comment_content'] = post.comment.content
  9.  
  10. result << single_post
  11. end
  12.  
  13. # return the result
  14. result
  15. end
  16.  
  17. namespace :post do
  18. task :comments => :environment do
  19. comments = Post.post_template
  20. puts comments
  21. end
  22. end
  23.  
  24. { 'comment_title' => 'stuff', 'comment_content' => 'content' }
  25. { 'comment_title' => 'stuff', 'comment_content' => 'content' }
  26. { 'comment_title' => 'stuff', 'comment_content' => 'content' }
  27.  
  28. > rails c
  29. > comments = Post.post_template
  30. -- [{ 'comment_title' => 'stuff', 'comment_content' => 'content' },
  31. { 'comment_title' => 'stuff', 'comment_content' => 'content' }]
  32.  
  33. namespace :post do
  34. task :comments => :environment do
  35. comments = Post.post_template
  36.  
  37. data = {}
  38. data['messages'] = comments
  39. end
  40. end
  41.  
  42. task :array do
  43. puts ["First", "Second"]
  44. end
  45.  
  46. > rake array
  47. First
  48. Second
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement