<h2>Search by Tag</h2>

<%= form_tag("/search", method: "get") do %>
  <%= label_tag(:q, "Search by Tag:") %>
  <%= text_field_tag(:q) %>
  <%= submit_tag("Search") %>
<% end %>

<h2>Resources</h2>
<div id='all-resources'>
  <ul>
    <% if @q %>
      <% @tags.each do |tag| %>

        <% if tag.name == @q.downcase %>

            <% tag.resources.each do |resource| %>
              <li><%= link_to resource.title, resource.url %> </li>
            <% end %>

        <% end %>

      <% end %>

    <% else %>
      <% @resources.each do |resource| %>
        <li><%= link_to resource.title, resource.url %> </li>
      <% end %>
    <% end %>
  </ul>
</div>

<h2>Search by Tag</h2>

<%= form_tag("/search", method: "get") do %>
  <%= label_tag(:q, "Search by Tag:") %>
  <%= text_field_tag(:q) %>
  <%= submit_tag("Search") %>
<% end %>

<h2>Resources</h2>
<div id='all-resources'>
  <ul>
    <% if @q %>
    <h3><%=@q.downcase%></h3>
      <% @tags.each do |tag| %>
        <% if tag.name == @q.downcase %>
            <% tag.resources.each do |resource| %>
              <li><%= link_to resource.title, resource.url %> </li>
            <% end %>
        <% end %>
      <% end %>

    <% else %>
      <% @resources.each do |resource| %>
        <li><%= link_to resource.title, resource.url %> </li>
      <% end %>
    <% end %>
  </ul>
</div>

Add search term as heading for list, cleaned up code spacing
Add search term as heading for list, cleaned up code spacing
