当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby - Ternary operator within Rails view

问题描述:

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' : '' %>">

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

网友答案:

You missed =

<li class="<%= is_current_page('') ? 'active' : '' %>">
网友答案:

You probably wanted to do

<li class="<%= is_current_page('') ? 'active' : '' %>">
网友答案:

this is what you need to do : <li class="<%= is_current_page('') ? 'active' : '' %>">

分享给朋友:
您可能感兴趣的文章:
随机阅读: