Rails 视图中的三元运算符 [英] Ternary operator within Rails view

查看:36
本文介绍了Rails 视图中的三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Rails 的新手,所以如果它很简单,请原谅我,但看起来好像我写的东西是正确的.在我看来,我正在使用三元运算符来决定是否添加一类活动:

I'm new to Rails, so forgive me if it's something simple, but it does seem as if though what I've written is correct. I'm using a ternary operator in my view to decide whether to add a class of active or not:

<li class="<% is_current_page('') ? 'active' : '' %>">

而且我已经调试并确定 is_current_page('') 正在返回 true.

And I've debugged and know for sure that is_current_page('') is returning true.

推荐答案

你错过了 =

<li class="<%= is_current_page('') ? 'active' : '' %>">

这篇关于Rails 视图中的三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆