Embed ERB Ruby Code in CSS in Rails

Did you know that you can embed erb code into CSS in rails? I just learned it, and its awesome, and simple.

Start by adding the .erb extension to your css file:

pages.css.erb

Then bam! you can put erb in your css code:

.navbar-brand {
background-image: url(<%= asset_path 'new-logo.png' %>);
background-size: contain;
background-repeat: no-repeat;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: