Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def self.post_template
- posts = Post.all
- result = []
- posts.each do |post|
- single_post = {}
- single_post['comment_title'] = post.comment.title
- single_post['comment_content'] = post.comment.content
- result << single_post
- end
- # return the result
- result
- end
- namespace :post do
- task :comments => :environment do
- comments = Post.post_template
- puts comments
- end
- end
- { 'comment_title' => 'stuff', 'comment_content' => 'content' }
- { 'comment_title' => 'stuff', 'comment_content' => 'content' }
- { 'comment_title' => 'stuff', 'comment_content' => 'content' }
- > rails c
- > comments = Post.post_template
- -- [{ 'comment_title' => 'stuff', 'comment_content' => 'content' },
- { 'comment_title' => 'stuff', 'comment_content' => 'content' }]
- namespace :post do
- task :comments => :environment do
- comments = Post.post_template
- data = {}
- data['messages'] = comments
- end
- end
- task :array do
- puts ["First", "Second"]
- end
- > rake array
- First
- Second
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement