How to write if-condition in Haml?

前端 未结 5 1425
长发绾君心
长发绾君心 2021-01-31 00:55

How to write if and if-else statements in Haml for a Ruby on Rails application?

5条回答
  •  梦毁少年i
    2021-01-31 01:45

    In haml two operators are used for ruby code.

    • = is used for ruby code which is evaluated and gets inserted into document.

    Example:

    = form_for @user  
    
    • - is used for ruby code which is evaluated and NOT get inserted into document.

    Example:

    - if @user.signed_in?  
      = "Hi"  
    - else  
      = "Please sign in!"
    

提交回复
热议问题