By the end of the week I will have completed my final Flatiron portfolio project. This last project really threw me in a loop and I must say it was by far the most time-consuming and challenging project I have worked on thus far. Learning Redux was quite difficult for me and it took awhile for me to understand the material as there are many files involved in a (or at least my) Redux project. So, I thought it would be helpful to provide a getting started guide for the frontend and backend as well as a build flow guide for Redux.
When creating a Rails API, it is best to follow these steps:
- cd to main directory
- $ rails new name_of_project_backend –api
-
Create repository on GitHub matching name above, then
$ git init
$ git add .
$ git commit -m “Generated project”
$ git remote add origin https://github.com/username/name_of_project_backend.git
$ git push -u origin master
- Decide which models you wish to create and assign attributes/relationships
- $ rails g scaffold model_name model_attribute ** OR rails g resource model_name …
- Uncomment CORS gem in Gemfile
-
Update routes and add namespacing
namespace :api do namespace :v1 do resources :model end end -
Create new folders in controller folder and move model controller into v1 folder
• controllers > api > v1 > model_controller.rb
- Add gem ‘jsonapi-serializer’ to Gemfile and bundle
- $ rails g serializer Model
- Add attributes that you want to show in the API to serializer
-
Update controller to use serializer
Example for show action:
def show model_json = ModelSerializer.new(@model).serializable_hash.to_json render json: model_json end
When creating a React app, it is best to follow these steps:
- cd to main directory
- $ create-react-app name_of_project
-
Create repository on GitHub matching name above, then
$ git init
$ git add .
$ git commit -m “Generated project”
$ git remote add origin https://github.com/username/name_of_project.git
$ git push -u origin master
When using Redux, it is helpful to follow this flow when building your store:
- Add component
- Add reducer
- Add reducer to store
- Build action creators
- Import connect into component
- Add const mapStateToProps
- Change export statement to connect
Hope that can help someone! Thanks for everything Flatiron!