2017-02-03 56 views
1

我正在做一個模塊化的應用程序:內聯模板不能與模塊一起使用?

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的,但隨後還挺不再模塊化它的工作原理。

+1

注[這裏](http://www.sinatrarb.com/intro.html#Inline%20Templates)似乎適用。你需要在不同的文件中使用sinatra嗎? – Anthony

+0

@Anthony,我在main.rb中放置了'enable:inline_templates'(在需要模塊之前),但沒有任何改變 – Nakilon

回答

0

已在另一種情況下相同的錯誤:

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[/[^:]+/]