0

Probably a newbie question, but when my user visits job#index I want to show a partial that is stored in my views/layouts called _subnav.html.erb.

This only needs to render when the user is at jobs#index.

Can someone help me with this but also understand how it works.

Shaun Frost Duke Jackson
  • 1,256
  • 1
  • 10
  • 22
  • Do you want to include the nav in a layout template? Is there a reason why `render partial: 'layouts/subnav'` within `jobs/index` will not suffice? – Damien Roche Dec 14 '13 at 16:53
  • I tried that and it just puts the partial across the whole index, rather than where I need it. Basically I'm just trying to include the sub navbar under the navigation bar when the user is on jobs#index. – Shaun Frost Duke Jackson Dec 14 '13 at 16:56

1 Answers1

1

I'd suggest you use content blocks.

Within your layout file, such as layout/application.haml, place this code where you want the subnav to be rendered:

= content_for :subnav

..and within your view file (jobs/index.haml)

- content_for :subnav
    = render partial: 'layouts/subnav'

Couple of alternatives:

  1. Check controller#action in layout file and only show for jobs#index
  2. Add a simple @show_sub_nav instance variable and set to true within your controller. In your layout file: = render partial: 'layouts/subnav' if @show_sub_nav

You can see how to achieve (2) with my answer here.

Community
  • 1
  • 1
Damien Roche
  • 13,189
  • 18
  • 68
  • 96