Search code examples
ruby-on-railsrenderingrenderpartial

Loading a nav bar when in a specific controller rails


I am having a bit of trouble in rails.

What I want to do is to display some extra links in the application layout when a specific controller is in use. How do I do this?

I am loading the pages dynamically using jquery and I tried using <%if controller_name == "foo"%> then do some magic, without any success.

If somebody could point me in the right direction or even a jquery-rails rendering tutorial that would be great.

Thanks.


Solution

  • Check out the content_for magic provided by Rails. It allows you to specify something like this in your application layout:

    <%= yield :header %>
    

    And then in your individual templates do something like this:

    <% content_for :header do %>
      Content I want put in the header
    <% end %>
    

    Which basically results in the content inside the content_for block being captured and rendered at the point of the yield statement. So, you can specify that in the templates for your controller.