【发布时间】:2017-05-11 09:47:19
【问题描述】:
我有一个用 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,一切都会按预期工作。但是我不想继承完整类的臃肿,我需要苗条的 API 版本。
我尝试添加诸如 ActionController::Renderers::All 和 AbstractController::Rendering 之类的模块,但没有成功。
【问题讨论】:
-
试试
render_to_string file: 'public/index' -
@Md.FarhanMemon 空响应
-
添加扩展看看,
.html -
@Md.FarhanMemon 还是空的
-
你试过
render html: 'file_name'吗?
标签: ruby-on-rails ruby url-routing single-page-application