Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在rails之外呈现html文件_Ruby On Rails - Fatal编程技术网

Ruby on rails 在rails之外呈现html文件

Ruby on rails 在rails之外呈现html文件,ruby-on-rails,Ruby On Rails,我试图呈现一个html文件,该文件不在rails项目中,但使用rails作为路由 我一直在尝试设置这样的路径,但它将尝试链接到公用文件夹中的文件 get '/pathtofile', :to => redirect("/path/to/the/other/file.html") 我也尝试过在控制器中呈现另一个文件,但没有成功 render "/path/to/the/other/file.html" 有什么方法可以做到这一点吗?您可以通过多种方式自定义Rails用于查找视图模板的路径,

我试图呈现一个html文件,该文件不在rails项目中,但使用rails作为路由

我一直在尝试设置这样的路径,但它将尝试链接到公用文件夹中的文件

get '/pathtofile', :to => redirect("/path/to/the/other/file.html")
我也尝试过在控制器中呈现另一个文件,但没有成功

render "/path/to/the/other/file.html"

有什么方法可以做到这一点吗?

您可以通过多种方式自定义Rails用于查找视图模板的路径,包括:

# example one
class ProjectsController < ApplicationController
  prepend_view_path 'app/views/mycustomfolder'

# example two
class ProjectsController < ApplicationController
  def self.controller_path
    "mycustomfolder"
  end
#示例一
类ProjectsController<应用程序控制器
前置\视图\路径“app/views/mycustomfolder”
#例二
类ProjectsController<应用程序控制器
def自我控制器路径
“mycustomfolder”
终止
从理论上讲,你可以用它完全退出应用程序,这就是你要求做的:

class ProjectsController < ApplicationController
  prepend_view_path 'app/../..' # you are now in the parent folder of the app itself
class ProjectsController
但我认为这将是一个脆弱的解决方案。例如,当你托管你的应用程序时,链接到的文件将不与之匹配,你的链接将断开。应用程序是由其根文件夹定义的,您在应用程序中链接到的所有内容最好位于应用程序的文件夹树中,或者可以通过URI访问