posts controller action implementation, models and javascript refactoring