2017-05-02 30 views
0

鑑於a really simple Sinatra application我們如何在Sinatra應用程序中的Slim模板中呈現隨機部分?

require 'sinatra' 
require 'slim/include' 

get '/' do 
    @specifically = %W(milk bread cheese).sample 
    slim :home 
end 

views/home.slim看起來是這樣的:

doctype html 
html 
    head 
    title Don't forget the stuff 

    body 
    include reminder 

我們可以看到,reminder包括作爲裸字(而不是String)。

views/reminder.slim,我想包括由可變@specifically表示的隨機部分:

p Remember the things! 

include @specifically 

這就提出了一個在Temple::FilterError/'@specifically.slim' not found

我該如何讓Slim在這裏呈現milk.slim(或其他)?

回答

0

Rubber ducking This worked

而不是

include @specifically 

使用

== slim @specifically.to_sym 
+0

我找不到這種方法記錄任何地方,所以會離開這個答案讓別人找到,而不是刪除的問題。 – Johnsyweb

相關問題