有没有办法在Slim中为以下示例编写case语句。我对StackOverflow问题进行了一些更改:How to write a switch statement in Ruby
case a
when 1..5
= "It's between 1 and 5"
when 6
= "It's 6"
when String
= "You passed a string"
else
= "You gave me #{a} -- I have no idea what to do with that."
end
我尝试了以下操作但产生错误。
= case @taxon.name
= when "Wedding Cakes"
div.taxon-descripiton Wedding Cake Description
这就是我所说的
... syntax error, unexpected tIVAR, expecting keyword_when
; @output_buffer.safe_concat(("<when>\"Weddin...
答案 0 :(得分:15)
=
,当你想要调用某些ruby逻辑而不在视图中渲染任何你应该使用-
的东西时:
- case @taxon.name
- when "Wedding Cakes"
div.taxon-descripiton Wedding Cake Description
我不确定这会解决你的问题,你有没有考虑过把这个逻辑转移到装饰师身上?