Sinatra 子目录视图 [英] Sinatra Sub-Directory Views

查看:57
本文介绍了Sinatra 子目录视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从 ./views 的子目录(例如 ./views/admin)获取 Sinatra 视图.我知道您可以像这样设置视图:

I want to be able to get Sinatra views from sub-directories of ./views (such as ./views/admin). I know you can set the views like so:

set :views, Proc.new { File.join(root, "templates") }

但是我怎么才能只为文件的一部分设置这个?

But how would I be able to set this for only part of the file?

推荐答案

我不确定您要问什么,但是您可以通过执行以下操作在 views/admin 中呈现视图:

I'm not sure exactly what you're asking, but you can render a view in views/admin by doing this:

erb :"admin/report"

如果您在调用 erb :report 时询问如何自动查看 views 的子目录,我不知道该怎么做,我不知道不认为您想要(如果不同目录中的两个视图具有相同的名称会发生​​什么?).

If you're asking how to automatically look in subdirectories of views when you call erb :report, I'm not sure how to do that, and I don't think you'd want to (what happens if two views in different dirs have the same name?).

这篇关于Sinatra 子目录视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆