在控制器操作中从公共服务文件

asf*_*ows 1 asset-pipeline ruby-on-rails-4

在我的项目中,我们有一个单页应用程序,并且构建过程将应用程序编译为一个静态文件,位于public/index.html

单页的应用程序负责处理在应用中的所有路由,所以无论你是否登陆site.comsite.com/foo/bar/action或者site.com/?,我想Rails应用程序服务public/index.html

我有这条路线:

match '*path', to: 'foo#index', via: :all
Run Code Online (Sandbox Code Playgroud)

在FooController中:

class FooController < ApplicationController
  def index
    render 'index.html', layout: false
  end
end
Run Code Online (Sandbox Code Playgroud)

这不符合我的期望。我得到错误Missing template foo/index.html, application/index.html

public作为Rails控制器动作的一部分,是否可以提供资产?

Kev*_*vin 5

在Rails 5中,我这样做

render file: "public/examplename.html", layout: false
Run Code Online (Sandbox Code Playgroud)