Created
November 17, 2010 00:30
-
-
Save kristjan/702789 to your computer and use it in GitHub Desktop.
Helpers to use Rails image_paths in CSS background images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AssetsHelper | |
def background_images(images) | |
content_for :head do | |
content_tag(:style, :type => 'text/css') do | |
images.map{|selector, path| css_background_image(selector, path)}. | |
join("\n") | |
end | |
end | |
end | |
def css_background_image(selector, given_path) | |
c_a = "#{params[:controller]}/#{params[:action]}" | |
path = given_path =~ %r{/} ? given_path : "#{c_a}/#{given_path}" | |
<<-CSS | |
#{selector} { | |
background-image: url('#{image_path(path)}'); | |
} | |
CSS | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment