我怎么能只写一次"Text"并同时检查path_info是否包含'A'?

ham*_*ser 5 ruby haml

- if !request.path_info.include? 'A'
  %{:id => 'A'}
   "Text"
- else
  "Text"
Run Code Online (Sandbox Code Playgroud)

"文字"写了两次.我怎么能只写一次并同时检查path_info是否包含'A'?

Eri*_*rik 2

您可以使用以下构造使属性成为条件:

%{:id => ('A' if request.path_info.include? 'A')}
  "Text"
Run Code Online (Sandbox Code Playgroud)