Reputation: 111030
Right now I have the following:
<% if [email protected]? && @thread.name == 'X' || @thread.name == 'Y' %>
....
The problem here is that I believe regardless if [email protected]?, @thread.name is still be called which is causing errors.
What's the right way to write this so it's like:
<% if [email protected]? && @thread.name == ('X' || 'Y') %>
Some type of contained in a list? for the thread.name?
Thanks
Upvotes: 2
Views: 154
Reputation: 146123
['x', 'Y'].include?(@thread.try(:name))
or
['x', 'Y'].include? @thread.try :name
Upvotes: 3
Reputation: 11628
if @thread.present? and ['X', 'Y'].include?(@thread.name)
Edit: More info on #present?
.
Upvotes: 4
Reputation: 20724
The try method could make this code more clearer. Take a look at this http://everydayrails.com/2011/04/28/rails-try-method.html.
Upvotes: 3