SVG Swap Rails
This gem wraps up the jQuery plugin by teleject for the asset pipeline.
Setup
gem 'svg-swap-rails'
Add the following to the app/views/layouts/application.html.erb
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
Add the following to app/assets/javascripts/application.js
//= require svg_swap_rails
Usage
Use the Rails image_tag helper with the class 'svgswap' and 'data-svgswap' attribute.
<%= image_tag('svg_version.svg', :class => 'svgswap', :data => { :svgswap => image_url('png_version.png') }) %>