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

ruby on rails - Is there a simple way only output if variable in in a comma separated list?

问题描述:

This is my code.

What I want to do is only show STAXCODE if the state is in this list. AL,FL,CO

<% @ship_states.each do |state| %>

<%= state.STAXCODE %>

<% end %>

网友答案:

try,

<% @ship_states.each do |state| %>
  <%= ['AL', 'FL', 'CO'].include?(state.STAXCODE) ? state.STAXCODE : nil  %>
<% end %>
分享给朋友:
您可能感兴趣的文章:
随机阅读: