Ruby On Rails API-Only 模式使用 jbuilder

环境

  • rails 6.0

  • ruby 2.6.5

步骤

  1. 打开 Gemfile 找到 # gem 'jbuilder', '~> 2.7',取消掉这行的注释

  2. 执行 bundle install

  3. 打开 app/controller/application_controlle.rb 文件,在 ApplicationController 类中加入两行

class ApplicationController < ActionController::API
  include ActionController::ImplicitRender		# 新加的
  include ActionView::Layouts	# 新加的
end
  1. 重启 rails s 即可

评论