我们如何在Sinatra应用程序中的Slim模板中渲染随机部分?

时间:2017-05-02 09:59:06

标签: ruby sinatra slim-lang

鉴于a really simple Sinatra application

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(或其他)?

1 个答案:

答案 0 :(得分:0)

Rubber duckingworked

而不是

include @specifically

使用

== slim @specifically.to_sym