elsif声明在视图中不起作用

时间:2014-11-19 18:27:39

标签: ruby-on-rails

我需要帮助理解Rails视图中elseif语句的用法。我以前做过,但现在我正在用SLIM做这件事而我似乎无法让它发挥作用。我希望它能打印出#34;他"或者"她"取决于当前用户gender。我正在使用的代码是用文本打印出elsif语句。

            a.profile_btn href="#" data-mfp-src='#ask_me' 
              img alt="" src="/assets/login_icon2.png" /
          if current_user.gender == "male"
              span Ask Him Out
          elsif current_user.gender == "female"
                span Ask Her Out

原始代码:

            a.profile_btn href="#" data-mfp-src='#ask_me' 
              img alt="" src="/assets/login_icon2.png" /
              span Ask This User Out

1 个答案:

答案 0 :(得分:1)

尝试

- if current_user.gender == "male"
   span Ask Him Out
- elsif current_user.gender == "female"
   span Ask Her Out