Refactor update method in posts_controller