1

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 %>
0

1 Answer 1

1

try,

<% @ship_states.each do |state| %>
  <%= ['AL', 'FL', 'CO'].include?(state.STAXCODE) ? state.STAXCODE : nil  %>
<% end %>
Sign up to request clarification or add additional context in comments.

2 Comments

UPDATE: Your code did work. I found that the state codes in the database have a trailing space after each so 'FL' is actually 'FL '. Is there a good way to deal with that? Thanks in advance
Sure, state.STAXCODE.strip should get rid of those spaces for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.