<div id="media_gallery">

  <% @media.in_groups_of(5, false) do |media_row| %>
    <div class="row">
      <% media_row.each do |media| %>
        <%= render partial: "storytime/dashboard/media/media.html.erb", locals: { media: media } %>
      <% end %>
    </div>
  <% end %>

  <%= paginate @media, remote: true, params: { controller: "dashboard/media",
                                               action: "index",
                                               id: nil,
                                               large_gallery: @large_gallery.nil? ? true : @large_gallery } %>
</div>

<div id="media_gallery">
  <% if @media.any? %>
    <% @media.in_groups_of(5, false) do |media_row| %>
      <div class="row">
        <% media_row.each do |media| %>
          <%= render partial: "storytime/dashboard/media/media.html.erb", locals: { media: media } %>
        <% end %>
      </div>
    <% end %>

    <%= paginate @media, remote: true, params: { controller: "dashboard/media",
                                                 action: "index",
                                                 id: nil,
                                                 large_gallery: @large_gallery.nil? ? true : @large_gallery } %>
  <% end %>
</div>

Add nil check to media gallery
Add nil check to media gallery
