Skip to content

Instantly share code, notes, and snippets.

View pascalesdedy's full-sized avatar

Pascales Kurniawan pascalesdedy

  • Not All Who Wander Are Lost - JRR Tolkien
  • Yogyakarta
View GitHub Profile
@pascalesdedy
pascalesdedy / articles_controller.rb
Created October 21, 2018 19:18
app/controller/articles_controller.rb - Simple rails api server TDD
class ArticlesController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :set_article, only: [:show, :update, :destroy]
# GET /articles
def index
@articles = Article.all
json_response(@articles)
end
@pascalesdedy
pascalesdedy / response and exception_handler .rb
Created October 21, 2018 19:25
app/controller/concerns files - Simple Rails API server - TDD
#app/controller/concerns/response.rb
module Response
def json_response(object, status = :ok)
render json: object, status: status
end
end
#app/controller/concerns/exception_handler.rb
module ExceptionHandler
# provides the more graceful `included` method
@pascalesdedy
pascalesdedy / response and exception_handler .rb
Created October 21, 2018 19:25
app/controller/concerns files - Simple Rails API server - TDD
#app/controller/concerns/response.rb
module Response
def json_response(object, status = :ok)
render json: object, status: status
end
end
#app/controller/concerns/exception_handler.rb
module ExceptionHandler
# provides the more graceful `included` method
@pascalesdedy
pascalesdedy / application_controller.rb
Created October 21, 2018 19:27
app/controller/application_controller.rb - Rails api server using TDD
class ApplicationController < ActionController::API
include Response
include ExceptionHandler
end
r = require('rethinkdb');
var connection = null;
r.connect( {host: 'localhost', port: 28015}, function(err, conn) {
if (err) throw err;
connection = conn;
r.db('test').tableCreate('authors').run(connection, function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));