Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know in what environment the code runs?

In the layout file of haml I would like to determine whether we are in our development and build environments. We're using Middleman.

I would like to do something like this:

- if environment == 'development'
    / Development Code
    = javascript_include_tag "Dev.js"

I tried to access Ruby's environment variable, as well as define a custom variable in the config.rb file with no success.

like image 934
IgalSt Avatar asked Dec 09 '12 10:12

IgalSt


1 Answers

You’ve almost got it right – you need to check against a symbol rather than a string:

- if environment == :development
    / Development Code
    = javascript_include_tag "Dev.js"

Middleman also adds the development? and build? methods which may be easier to use:

- if development?
    / Development Code
    = javascript_include_tag "Dev.js"

This works with ERB too:

<% if development? %>
<!-- Development Code -->
<%= javascript_include_tag "Dev.js" %>
<% end %>
like image 96
matt Avatar answered Oct 12 '22 02:10

matt