I am stuck on what seems should have a very simple solution, but I can not find anything that will work! I am iterating results from a table on the index page (which returns a list of states). This works without any problems when multiple records are returned. However, when a single record is returned, I get an error: undefined method 'each' for #
I know it is causing the error when only one record is returned, but I can not find any documentation on how to handle this, especially in the case that 1 or 0 records could be returned.
Code in controller:
@states = State.find(params[:id])
Code in index page:
<ul>
<% @states.each do |state| %>
<li>
<%= state.state_name %>
</li>
<% end %>
</ul>