我有一个用React编写的单页面应用程序和Ruby on Rails后端(API模式).Rails也提供静态文件.我指的是Rails路由器public/index.html,所以我的SPA可以管理他自己的路由react-router.这是通常的做法,以便使直接链接和刷新工作.
的routes.rb
match '*all', to: 'application#index', via: [:get]
Run Code Online (Sandbox Code Playgroud)
application_controller.rb
class ApplicationController < ActionController::API
def index
render file: 'public/index.html'
end
end
Run Code Online (Sandbox Code Playgroud)
问题是这在API模式下不起作用.这只是一个空洞的回应.如果我将父类更改为ActionController::Base一切按预期工作.但我不想继承全班的膨胀,我需要纤薄的API版本.
我尝试过添加模块ActionController::Renderers::All,AbstractController::Rendering无论是否成功.