DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Tatjana has posted 5 posts at DZone. View Full User Profile

Developer Info On Every Page

06.06.2008
| 942 views |
  • submit to reddit
        First, make a file in your /app/views/common_partials folder called ‘_developer_info.html.erb’

Into this, throw the following:
<a id="DevInShow" href="#" 
   style="font-size:small;position:absolute;bottom:10px;right:10px"
   onclick="$('DevInfo').show(); $('DevInShow').hide();">
 Show Developer Info</a>

<div id="DevInfo" 
     style="background:white;padding: 5px;
            border:10px solid red;position:absolute;
            top:0px;left:0px;display:none">

  <a href="#" 
     onclick="$('DevInfo').hide(); $('DevInShow').show();">
  Hide Developer Info</a>

  <h1>Params</h1>
  <pre>
    <%= params.to_yaml %>
  </pre>
  <h1>Session</h1>
  <pre>
    <%= session.to_yaml %>
  </pre>
  <a href="#" 
        onclick="$('DevInfo').hide();$('DevInShow').show();">
  Hide Developer Info</a>
</div>
The above code sets up a hidden div in your view with a link at the bottom right. When you click the link it makes the hidden div visible (which is absolutely positioned over the top of all your content) and gives you a link to click it away again. Neat.

Now, to make all this Rails-foo goodness work, add the following to the very bottom of your application.html.erb file, just before the </body> tag is good.
<%- if RAILS_ENV == "development" -%>
  <%= render :partial => 'common_partials/developer_info' %>
<%- end -%>