Can someone explain the following code to me?

前端 未结 5 1737
故里飘歌
故里飘歌 2021-01-20 05:59

I am following along with the Rails 3 in Action book, and it is talking about override to_s in the model. The code is the following:

def to_s
           


        
5条回答
  •  旧时难觅i
    2021-01-20 06:15

    Actually admin? is a function(probably defined somewhere in controller/helper method or model) that return boolean(true or false) and next question mark is just like a if condition

    if admin? == true
     "Admin"
    else
     "User"
    

    first portion before ":" is for true case and other is for false case

提交回复
热议问题