Today was a hard day, I found out some heartbreaking stuff and I am really saddened by it, but they say he gives his toughest tasks to his strongest soldiers. I have to keep going.
Below is the repo, I wrote the steps I took in the README.md.
#Step By Step Build
#Setting Up The Rails API
- Create a folder
- cd into
- Create a new rails app -- ``rails new -api --database-postgresql
- cd into the new-app-name
- Uncomment out
- Run bundle
- Go to your
Uncomment/add the following code:
Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins '*' resource '*' headers: :any methods: [:get, :post, :put, :patch, :delete, :options, :head] end end
#Create a controller:
- rails g controller notes
- Create a version folder.
- Add controller into version folder -->
- Namespace the controller:
class Api::V1::NotesController < ApplicationController end
- Add data into your controller -- rememeber to render json
class Api::V1::NotesController < ApplicationController def index @notes = Note.all render json: @notes, status: 200 end def show @note = Note.find(params[:id]) render json: @note, status: 200 end def create @note = Note.create(note_params) render json: @note, status: 200 end def update @note = Note.find(params[:id])
I did not get to finish the code along but I did learn a lot. Feel free to use the step by step guide I provided in the readme.
Thanks for reading!