This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::API | |
include Response | |
include ExceptionHandler | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
OlderNewer