Create a postgresql user called 'live-chair' with the password 'live-chair'
rake db:create
Let's say we already have a resource for barbers and we want a function to list all barbers
Add the resource under the api version 1 namespace
namespace :api, defaults: {format: 'json'} do
namespace :v1 do
resources :barbers
end
Make a new controller at app/controllers/api/v1/barbers_controller.rb. a. Notice because of the namespacing our controller class is nested in two modules. b. We are using respond_to :json at the class level because rails will throw an error otherwise :/
Encapsulate the controller in the Api and V1 module
module Api
module V1
class BarbersController < ApplicationController
respond_to :json
end
end
end
Add necessary index function
def index
@barbers = Barber.all
end`
There's no need to add anything else because rabl is handling the view and our routes.rb and our class know to render json. We don't even have to say render
Make a rabl file at app/views/api/v1/barbers/index.json.rabl to determine which parameters to provide in json format.
collection @projects
attributes :id, :name`
Point your browser to localhost:3000/api/v1/barbers and you should have some awesome JSON!
You can copy this test I did to get you started.
module Api
module V1
class ProjectsController < ApplicationController
respond_to :json
def index
@projects = Project.all
end
def show
respond_with Project.find(params[:id])
end
def create
respond_with Project.create(params[:product])
end
def update
respond_with Project.update(params[:id], params[:products])
end
def destroy
respond_with Project.destroy(params[:id])
end
end
end
end
collection @projects
attributes :id, :name
It is essential we stick with this work flow, especially the 'how to merge' section below will help us contain merge conflicts
1. git checkout master
2. git pull --rebase origin master
3. git checkout mm-sign-up
4. git rebase -i master
5. git checkout master
6. git merge mm-sign-up
7. git push origin master
1. git push origin :mm-sign-up
2. git branch -d mm-sign-up