skip to Main Content

I’m building a website for my new company and want to create a landing page for my product that doesn’t have a nav bar or a footer. I want to keep the landing page simple and just focus on the product.

I’m coding in Ruby on Rails. Twitter Bootstrap is what I’m using for styling the nav bar and footer.

My home page and about page have a nav bar and footer, but I don’t want my product landing page to have the nav bar and footer.

Any suggestions on how I can hide the nav bar and footer on my landing page, but keep it on my other pages?

4

Answers


  1. Yes , you can do it . One easy way is to use a different layout file for the landing page controller other than the default application.html.erb . In your desired template page write a custom layout name which will hold up the different kinds of specification . Let me give an example ,

    class SiteController < ApplicationController
      layout "landing_page"
      ...
    end
    

    This will load up a different layout with different view as you want for your site , while the default layout can hold the basic navbar and products for other pages.

    Thanks . Hope this one way will solve your problem .

    Visit This link for more information . ActionView API Docs

    Login or Signup to reply.
  2. To add to code.prio‘s answer, you could just use a conditional statement in your application layout (saves the hassle of maintaining two layouts):

    #app/views/layouts/application.html.erb
    <% unless controller_name == "landing" %>
       ... navbar ...
    <% end %>
    

    Not as pretty as the other answer, but works better. If you have more than one layout, it gets annoying having to maintain them both.

    Login or Signup to reply.
  3. I had the same problem, and I solved it this way:

    #app/views/layouts/application.html.erb
    <% unless action_name == "landing" %>
       ... navbar ...
    <% end %>
    

    using action_name instead of controller_name.

    Login or Signup to reply.
  4. It’s very simple:

        # application.html.erb
        <% unless action_name == "index" %>
           # render the footer partial "_footer.html.erb" file from "shared" folder
           <%= render 'shared/footer' %>
        <% end %>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search