0

My _footer.html.erb is (simplified):

<footer class="footer">
  <nav class="navbar navbar-default navbar-fixed-bottom navbar-inverse">
      <% if logged_in? %>
         <li class="btn btn-primary"> <%= link_to 'Add New Connection', new_year_path %></li>
         <li class="btn btn-primary"> <%= link_to 'Add New Person', new_person_path %> </li>
         <li class="btn btn-primary"> <%= link_to 'Add New Address/Location', new_location_path %> </li>
      <% end %>
  </nav>
</footer>

But I don't want the footer to show up while editing; too easy to click on one of these buttons instead of Cancel or Submit which is down the page and my footer is stuck to the bottom. views/layouts/application.html.erb has <%= render 'layouts/footer' %>

I suppose I could have my three edit.html.ergs not use the defaults above, but seems easier if I could add another condition on the _footer.html.erg. Or some other way. Maybe something about leaving page without submitting?

Based on @tsrandrei comment I tried wrapping the footer in <% if !current_page?(action: 'edit') %> blah-blah <% end %> but then get error No route matches {:action=>"edit", :controller=>"…"} with the controller name being whatever the page is relevant to.

Greg
  • 2,359
  • 5
  • 22
  • 35

1 Answers1

3
<% if current_page?(action: 'edit') %>
  <footer class="footer">
    <nav class="navbar navbar-default navbar-fixed-bottom navbar-inverse">
      <% if logged_in? %>
         <li class="btn btn-primary"> <%= link_to 'Add New Connection', new_year_path %></li>
         <li class="btn btn-primary"> <%= link_to 'Add New Person', new_person_path %> </li>
         <li class="btn btn-primary"> <%= link_to 'Add New Address/Location', new_location_path %> </li>
      <% end %>
  </nav>
 </footer>
<% end %>

See https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-current_page-3F

You will also have other methods for your views:

  • controller_path
  • controller_name
  • action_name

Also check Rails: How to determine controller/action in view

tsrandrei
  • 89
  • 1
  • 5
  • 1
    Missing the bang. But close enough. Thank you – Greg Nov 28 '19 at 21:19
  • I thought this was working. It does if one stays on the `/edit` page, but on most any other page, the error `No route matches {:action=>"edit", :controller=>"years"}` or similar. The error has different controllers depending on the page visited. PS. I did change to `<% if !current_page?(action: 'edit') %>` and thinking this might be part of the error changed back to `<% if current_page?(action: 'edit') %>` with and` if else` but still get errors. – Greg Dec 01 '19 at 21:49