refactoring code to more DRY in posts_controller.rb and comments_controller.rb