Reputation: 1019
I have the following HTML in my index file.
<% @posts.each_with_index do |post, index| %>
<tr>
<td><%= index+1 %></td>
<td><%= post.team_elo %></td>
<td><%= post.team_name %></td>
</tr>
<% end %>
I have a function called is_eligible
which takes post.team_name
as an argument. I want to run it each "do iteration" and skip all three printing steps if it returns false
I'm not sure how to
Any ideas?
Upvotes: 0
Views: 99
Reputation: 3661
# The view
<% @posts.each_with_index do |post, index| %>
<% unless post.is_eligible? %>
<tr>
<td><%= index+1 %></td>
<td><%= post.team_elo %></td>
<td><%= post.team_name %></td>
</tr>
<% end %>
<% end %>
# The model post.rb
def is_eligible?
# and there you use self.name to access the name
end
Upvotes: 4
Reputation: 160963
<% @posts.select{|p| is_eligible(p. team_name)}.each_with_index do |post, index| %>
<tr>
<td><%= index+1 %></td>
<td><%= post.team_elo %></td>
<td><%= post.team_name %></td>
</tr>
<% end %>
Upvotes: 1