仅在HAML中如何显示某些内容?

时间:2018-10-08 16:44:55

标签: ruby-on-rails haml

我有一个环境变量:

ONETRUST_SRC: 'https://somesite'

我尝试过:

- if ENV['ONETRUST_SRC']?
  = javascript_include_tag ENV['ONETRUST_SRC']
  :javascript
    function myfunc() { }

这给了我一个奇怪的错误:

syntax error, unexpected ';', expecting ':'

1 个答案:

答案 0 :(得分:1)

结尾的?导致此错误(expecting ':'是因为在这种情况下?被解释为三元运算符)。

将if语句更改为使用present?

- if ENV['ONETRUST_SRC'].present?
  = javascript_include_tag ENV['ONETRUST_SRC']
  :javascript
    function myfunc() { }