One line if statement not working

前端 未结 8 909
遥遥无期
遥遥无期 2021-01-29 18:59
<%if @item.rigged %>Yes<%else%>No<%end%>

I was thinking of something like this?

if @item.rigged ? \"Yes\" : \"No\" 
<         


        
相关标签:
8条回答
  • 2021-01-29 19:44

    From what I know

    3 one-liners

    1. a = 10 if <condition>

    example:

    a = 10 if true # a = 10
    b = 10 if false # b = nil
    
    1. a = 10 unless <condition>

    example:

    a = 10 unless false # a = 10
    b = 10 unless true # b = nil
    
    1. a = <condition> ? <a> : <b>

    example:

    a = true ? 10 : 100 # a = 10
    a = false ? 10 : 100 # a = 100
    

    I hope it helps.

    0 讨论(0)
  • 2021-01-29 19:48

    if else condition can be covered with ternary operator

    @item.rigged? ? 'Yes' : 'No'
    
    0 讨论(0)
提交回复
热议问题