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