ruby – 在Sinatra中配置erb目录
发布时间:2020-12-17 01:50:13 所属栏目:百科 来源:网络整理
导读:应用程序/控制器/ app.rb require 'sinatra'get '/' do erb :indexend 应用/视图/ index.erb html body pHello World/p /body/html 错误: Errno::ENOENT at /No such file or directory - .../app/controllers/views/index.erb 如何配置erb以查看app / view
应用程序/控制器/ app.rb
require 'sinatra' get '/' do erb :index end 应用/视图/ index.erb <html> <body> <p>Hello World</p> </body> </html> 错误: Errno::ENOENT at / No such file or directory - .../app/controllers/views/index.erb 如何配置erb以查看app / views而不是app / controllers / views? 解决方法
您可以通过调整配置设置来实现此目的.由于您使用的是非标准设置,因此您需要告诉Sinatra应用程序的实际根目录以及查找视图的位置.在app / controllers / app.rb文件的顶部添加:
# sets root as the parent-directory of the current file set :root,File.join(File.dirname(__FILE__),'..') # sets the view directory correctly set :views,Proc.new { File.join(root,"views") } 您可以在Sinatra Documentation中阅读有关Sinatra configuration options的更多信息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |