Spance Spance - 6 months ago 29
HTML Question

Exclude a partial from certain views

in my current Rails app, I have a partial in my layouts folder for a navigation sidebar. I would like this sidebar to render for every page of my app except the

new
and
thankyou
actions of my score controller, because those two views are going to be a part of an iframe. To do this, I'm making another layout called
iframe.html.erb
where I'd like to put the logic to exclude the navigation sidebar.

Here is my application.html.erb layout file

<!DOCTYPE html>
<html>
<head>
<title>NPS</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<div id="wrapper">

<%= render 'shared/navigation' %>
<%= yield %>
</div>

</body>
</html>


And here is my iframe.html.erb file

<!DOCTYPE html>
<html>
<head>
<title>NPS</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<div id="wrapper">

<%= if (current_page?(controller: 'scores', action: 'new') || current_page?(controller: 'scores', action: 'thankyou' )) do %>
<%= yield %>
<% end %>
</div>

</body>
</html>


I initially just had an
unless
statement in my application layout but that wouldn't work on the
sign-in
page because devise would be looking for those scores views in the devise folder. I'm also not very good with html.erb so I'm sorry if it's just a syntax thing.

Edit:

Here is the error I get with devise

ActionController::UrlGenerationError at /users/sign_in
No route matches {:action=>"new", :controller=>"devise/scores"}


Thanks

Answer

in your application.html.erb...

<%= render 'shared/navigation' unless @disable_nav %>

Then in your score controller where you have you have your two views...

def new
  @disable_nav = true
  # ...
end

def thankyou
  @disable_nav = true
  # ...
end
Comments