'Use if statement in layout.html.erb in a Sinatra app

Within my Sinatra application I would like to serve a minified version of my css/js for production but in development keep my default setup (individual files). I'm not quite sure how to write this in the correct syntax but if I give a pseudo-example, it should show what I am trying to achieve.

layout.html.erb

<% if :environment == :development %>
  <!-- stylesheet link tags here -->
<% elsif :environment == :production %>
  <!-- minified versions of stylesheets -->
<% end %>

is it possible to conditionally set which stylesheets I want to use, or is there a better way of doing this?

I am trying this

<% if ENV['RACK_ENV] = 'development' %>
  <!-- stylesheet link tags here -->
<% elsif ENV['RACK_ENV] = 'production' %>
 <!-- minified versions of stylesheets -->
<% end %>

Is there a more efficient way than this?



Solution 1:[1]

I have not used it yet, but it looks like sinatra-assetpack would provide an excellent solution for your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patru