Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Hiding a div based on Page using IF and ELSE statements

I have a home page where I want to display a div in a certain way that it will require to be in the top of the application view.

Div is classed as "HOME-BANNER"

I am attempting to create an IF ELSE statement to reflect hiding the div if it is not on the home page.

My question is how do I call the current page in order to identify it as the home view's index. Also would I end the code or do I place an else statement to continue the rest of the page?

<html>
<head>
  <title>WEBSITE</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>

<% if current_page == "home#index" %>
<div class="HOME-BANNER">


<% end %>


<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a href="#" class="brand">WEBSITE</a>
                <ul class="nav">
                    <li><%= link_to "All Jobs", jobs_path %></li>
                    <li><%= link_to "My Profile", tempers_path %></li>

                </ul>

                <div class="float-right">

                    <div class="btn-group open">
                          <a class="btn btn-primary" href="#"><i class="icon-user icon-white"></i></a>
                          <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
                          <ul class="dropdown-menu">
                            <li><i class="icon-pencil"></i><a href="<%= link_to '', edit_user_registration_path %>"> My Profile</a></li>
                            <li class="divider"></li>
                            <li><a href="#"><i class="icon-th-large"></i> Dashboard</a></li>
                            <li><a href="#"><i class="icon-th-list"></i> My Posts</a></li>
                            <li><a href=""><i class="icon-th-list"></i> My Searches</a></li>
                            <li><i class="icon-stop"></i> <%= link_to ' Sign out', destroy_user_session_path, :method => :delete %></li>
                          </ul>
                    </div>
                </div>
        </div>
    </div>
</div>

<div class="container"> 

    <p class="notice"><%= notice %></p>
    <p class="alert"><%= alert %></p>


    <%= yield %>
</div>
<div class="footer"></div>

</body>
</html>
like image 203
Andrew Avatar asked Aug 18 '12 21:08

Andrew


1 Answers

You want to do this from your controller. Since this is a localized event, use the controller that specifically hosts this View and not your application controller.

def whatever_view_this_is
  @home_banner  = true
end

Then in your view :

<% if @home_banner %>
  <div class="HOME-BANNER">
<% end %>
like image 95
Trip Avatar answered Oct 18 '22 12:10

Trip