amatsuda / jb

A simple and fast JSON API template engine for Ruby on Rails
MIT License
1.29k stars 43 forks source link

In rails 5 without "jbuilder" gem in Gemfile it returns "204 no content" #20

Closed arturaum closed 6 years ago

arturaum commented 6 years ago

If I delete in Gemfile line: gem 'jbuilder' it returns: Completed 204 No Content when I try to run http://localhost:3000/api/v1/customers/1 in browser

Some files:

# routes.rb
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :customers
    end
  end
end

# app/controllers/application_controller.rb
class ApplicationController < ActionController::API
  include ActionView::Rendering
end

# app/controllers/api_controller.rb
class ApiController < ApplicationController
  before_action :set_default_format

private

  def set_default_format
    request.format = :json
  end
end

# app/controllers/api/v1/customers_controller.rb
class Api::V1::CustomersController < ApiController
  before_action :set_customer, only: [:show, :update, :destroy]

  def show
  end

private

  def set_customer
    @customer = Customer.find(params[:id])
  end
end

# app/views/api/v1/customers/show.json.jb
json = {
    id: @customer.id,
    name: @customer.name
}

json
amatsuda commented 6 years ago

Addressed in #13 and #15. See https://github.com/amatsuda/jb/pull/13#issuecomment-438928162 for more details.