その1:名前一致しているか
ファイル名やルーティングが一致してないとエラーが出たり、JSON表示できない。
特に2回くらい複数形s
忘れしてるのでもう忘れない。
routes.rb
namespace :api, format: 'json' do
namespace :v1 do
resources :post_infos, only: [:index]
end
end
app/views/api/v1/post_infos/index.json.jbuilder
json.result 'success'
json.post_infos do
json.date @post_infos[:date]
json.genre @post_infos[:genre]
json.like_count @post_infos[:like_count]
end
その2:APIアプリケーションコントローラーを継承しているか
app/controllers/api/v1/post_infos_controller.rb
class Api::V1::PostInfosController < Api::ApplicationController
def index
...
end
end