sstephenson/sprockets — Issue #286: Access the fingerprint (or rack env) inside *.erb templates
Author: exviva
Created: 2012-01-26 18:23:18+00:00
State: open

I'm working on an application that should allow the user to change the look and feel of the application. I'd like to achieve this by saving the user's "theme" settings in a database, and then referencing the "current" theme's asset URL in the layout. Something like:

`app/views/layouts/application.html.erb`:

```html

...
```

Then, when the browser requests this URL, I'd like to programmatically access the HTTP request or at least the "id" part in the Sass/ERB template:

`app/assets/stylesheets/_theme_variables.css.scss.erb` (required by `theme.css`):

```erb
<%
fingerprint_from_the_url = '???' # Here I need to access the request, or at least the "fingerprint" part
theme = Theme.find(fingerprint_from_the_url)

theme.settings.each do |key, value| %>
$<%= key %>: <%= value %>;
<% end %>
```

After preprocessing with ERB, this should produce the following SCSS file:

```scss
$background_color: #eee;
$font_size: 16px;
```

depending on the settings stored in the Theme record.

Does this concept even make sense or maybe there's a better way to achieve it using Sprockets/Rails?

There are some caveats I can see, like what to do during precompilation (where obviously there is no request).

I'm willing to submit a patch, given acceptance and some guidance.