Find file
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (50 sloc) 1.88 KB


Build Status

Use fancybox with rails 3.1 asset pipeline.


This gem vendors jquery fancybox 2 for Rails 3.1 and greater. The files will be added to the asset pipeline and available for you to use.

First add the following lines to your applications Gemfile:

gem 'jquery-rails'
gem 'fancybox-rails'

Then run bundle install to update your application's bundle.

Now you need to edit your app/assets/javascripts/application.js file and add the following line:

//= require jquery
//= require fancybox

And then edit your app/assets/stylesheets/application.css file to look something like:

 *= require_self
 *= require fancybox
 *= require_tree .

That's it!


This gem initializes fancybox based on the data attribute "data-fancybox". This allows you to use fancybox out of the box like this:

<%= link_to "fancybox test", '#content_div', data: { fancybox: true } %>

You can also do more sophisticated things with fancybox 2, such as setting the content type. For example, for an AJAX request:

<%= link_to "fancybox ajax test", 'ajax_url', data: { fancybox: true, fancybox_type: 'ajax' } %>

However, you can still use fancybox as you might otherwise wish. For example, based on a class:

$(document).ready(function() {

See the fancybox Web site for more detailed usage documentation.

More information

Copyright (c) Chris Mytton


Fancybox 2 license