Tag: 单页面应用程序

如何在Rails 5 API中呈现文件?

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