HUS*_*TEN 1 ruby-on-rails ruby-on-rails-3
有没有办法在一行中对此进行编码?有点像<%="A"如果.......>
<% if @box == 'inbox' && m.is_read?(current_user) %>
A
<% else %>
B
<% end %>
Run Code Online (Sandbox Code Playgroud)
你需要一个三元运算符 - 在Ruby中也称为"条件"运算符,如果前面的表达式?为真,则返回"A" ,如果表达式为假,则返回"B".
<%= (@box == 'inbox' && m.is_read?(current_user)) ? "A" : "B" %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |