refactored the code to update posts_controller