内联模板不能与模块一起使用?
问题描述:
我正在做一个模块化的应用程序:内联模板不能与模块一起使用?
main.rb的
require "sinatra/namespace"
require "haml"
Dir.glob("servers/*/server.rb").each do |server|
require_relative server
end
我想要做的内联模板:
服务器/一些/ server.rb
namespace "/some/hello" do
get "/" do
haml :index
end
end
__END__
@@ index
!!!
%html
hello
但我得到的:
没有这样的文件或目录 - 视图/ index.haml
如果我移动模板main.rb的,但随后还挺不再模块化它的工作原理。
答
已在另一种情况下相同的错误:
main.rb的
require_relative "server_common"
get/do
haml :index
end
__END__
@@ index
!!!
.....
server_common.rb
require "sinatra"
.....
小号解决方案:
require "sinatra"
set :inline_templates, caller.first[/[^:]+/]
也必须添加此,因为Sinatra没有autorun。
set :app_file, caller.first[/[^:]+/]
注[这里](http://www.sinatrarb.com/intro.html#Inline%20Templates)似乎适用。你需要在不同的文件中使用sinatra吗? – Anthony
@Anthony,我在main.rb中放置了'enable:inline_templates'(在需要模块之前),但没有任何改变 – Nakilon