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.
I struggled with coding and felt overwhelmed by Javascript today, but luckily I have amazing friends who reminded me that I can do anything. So, I still attempted to create an app with a ruby on rails backend while watching a code along.
Below is the repo, I wrote the steps I took in the README.md.
README
#Step By Step Build
#Setting Up The Rails API
- Create a folder
mkdir todo-js-ruby
- cd into
mkdir todo-js-ruby
- Create a new rails app -- ``rails new -api --database-postgresql
- cd into the new-app-name
#Gemfile
- Uncomment out
gem 'rack-cors'
- Run bundle
- Go to your
config/initializers/cors.rb
file.
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.
app/controllers/api/v1
- Add controller into version folder -->
app/controllers/api/v1/notes_controller.rb
- 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!
Sincerely,
Brittany
Top comments (0)