I have a navigation bar included in
application.html.erb. Because for some pages, such as the signup page, I need to place additional code inside the navigation bar, I have excluded those pages for showing the navigation bar through
application.html.erb and instead included it in their respective view pages. See code below.
A problem arises when invalid data is entered in the signup form. The controller method then renders
application.html.erb then doesn't seem to recognize that the current_page is still
signup_path, therefore not applying the exception for not showing the navigation bar on that page. As a result when it renders new, the navigation bar is shown twice: once by order of
application.html.erb and once by order of the view page itself.
Why, when rendering new on an invalid form entry, does it not see that it's still on
signup_path? How should I adjust my code so that it does not show the navigation bar twice in that situation? Is there perhaps a way of including
<%= yield special code if any %> in
<% special_code %> <% end special_code %> in the view page that passes this special code to
In application.html.erb I have:
<% unless current_page?(signup_path) %> <nav class="banner"> <%= render partial: "shared/header" %> </nav> <% end %>
In the view of my signup page:
<nav class="banner"> <%= render partial: "shared/header" %> Additional code that needs to be within 'nav' for this page </nav>
def create @user = User.new(user_params) if @stakeholder.save flash[:success] = "A confirmation email has been sent to you." redirect_to root_url else render 'new' ###This is where it goes wrong! end end