Basically I have a table in the index view where if a pictures name = army.unit_name, then it renders that picture. If not, it displays in text that the image is missing. I’m still new at Rails, but there must be a way to put this conditional check somewhere else other than the view. Could someone please enlighten me? Do I do it in the model?
<% @armies.each do |army| %>
<tr>
<% if File.exists?("/users/<name>/Ruby Projects/thrones/app/assets/images/#{army.unit_name}.png") %>
<td><span class="picture-hover"><%= image_tag("#{army.unit_name}.png" %></span></td>
<% else %>
<td>Unit Card art missing</td>
<% end %>
<td><%= link_to army.unit_name, army_path(army) %></td>
</tr>
<% end %>
You can try this