超薄模板:如何解救异常?

Ale*_*ber 2 ruby erb slim-lang

我想将以下erb代码转换为slim.

<% begin %>
  <%= some_function %>
<% rescue Exception %>
  <%= some_other_function %>
<% end%>
Run Code Online (Sandbox Code Playgroud)

我的方法是:

- begin 
  = some_function
- rescue Exception 
  = some_other_function
Run Code Online (Sandbox Code Playgroud)

但这给出了一个错误:

index.slim:34: syntax error, unexpected keyword_ensure, expecting $end
Run Code Online (Sandbox Code Playgroud)

如何使用slim来正确地拯救异常?

ByS*_*pts 5

你需要做一个助手.

你应该把开始/救援逻辑放在那个帮助器里.

# my_helper.rb
class MyHelper
  def my_func
    begin
      some_function
    rescue
      some_other_func
    end
  end
end

# slim view
= my_func
Run Code Online (Sandbox Code Playgroud)