Ruby Slim模板:如何拯救异常?
我想将以下erb代码转换为slimRuby Slim模板:如何拯救异常?,ruby,erb,slim-lang,Ruby,Erb,Slim Lang,我想将以下erb代码转换为slim <% begin %> <%= some_function %> <% rescue Exception %> <%= some_other_function %> <% end%> 但这就产生了一个错误: index.slim:34: syntax error, unexpected keyword_ensure, expecting $end 如何正确使用slim拯救异常?您需要制作一
<% begin %>
<%= some_function %>
<% rescue Exception %>
<%= some_other_function %>
<% end%>
但这就产生了一个错误:
index.slim:34: syntax error, unexpected keyword_ensure, expecting $end
如何正确使用slim拯救异常?您需要制作一个助手 您应该将开始/救援逻辑放在该助手中
# my_helper.rb
class MyHelper
def my_func
begin
some_function
rescue
some_other_func
end
end
end
# slim view
= my_func
这实际上是一个,在slim 1.3.7中向上()
语法现在完全按照预期工作。没有辅助方法或缩进是必要的。幸运的是,这不再是必要的,请参阅下面的答案。
# my_helper.rb
class MyHelper
def my_func
begin
some_function
rescue
some_other_func
end
end
end
# slim view
= my_func