Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Applying partials to layouts in rails

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 72
    Comment on it

    In Rails we can use partials to organize our code in the layouts . This is generally helpful when we have layouts running up to hundreds of lines. For example we have a top nav bar which looks different for logged in and non logged in user. Then we can write the code for top nav bar in two different partial and render them in the layout. For example:

        <!DOCTYPE html>
        <html>
          <head>
            <title><%= title %></title>
            <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
            <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
            <%= csrf_meta_tags %>
          </head>
          <body>
            <header>
              <% if user_logged_in? %>
               <%= render 'layouts/logged_in_header' %>
              <%  else %>
               <%= render 'layouts/non_logged_in_header' %>
              <%  end %>
            </header>
          </body>
        </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: