RailsアプリをAPIモードで新規作成(rails new --api)して、一部機能だけ画面を作成したい時のやり方。
対象のコントローラーでApplicationControllerではなく、ActionController::Baseを継承させてあげれば良い。
あとは通常通り、Viewを用意するだけ。
-class ArticlesController < ApplicationController
+class ArticlesController < ActionController::Base
def feed
@articles = Article.all
end
end
APIモードで作成すると、ApplicationControllerは不要な機能を省いたAPI用のActionController::APIを継承している。
class ApplicationController < ActionController::API
end