Haml:更优雅的方式来编写标签 + ruby​​-表达式 + 字符串

win*_*ons 3 ruby haml ruby-on-rails

我的模板之一中有以下 haml 代码:

%b= t ('activerecord.attributes.exercise.title') + ':'
Run Code Online (Sandbox Code Playgroud)

有没有更优雅的方法来实现这一目标?最好是oneliner,没有括号。

Ala*_* H. 6

该解决方案我喜欢用是Haml的公司surroundsucceedprecede助手:

= surround '(', ')' do
  = link_to 'available here', foo_path


= precede '*' do
  = link_to 'source', foo_path


= succeed ':' do
  = link_to 'foo', foo_path
Text following link
Run Code Online (Sandbox Code Playgroud)

然后它只是在助手之前键入/粘贴一行并缩进助手。