Search code examples
ruby-on-railslightbox2

lightbox2 not working in rails 4


I downloaded lightbox and added the lightbox.js file to app/assets/javascripts and the lightbox.css file to app/assets/stylesheets. This is my application.js code:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require lightbox
//= require_tree .

This is my application.css.scss code:

@import "bootstrap-sprockets";
@import "bootstrap";
@import "lightbox";
@import "main";

I then moved the next, prev, loading, and close images to public/images in the rails app. I used MiniMagick and CarrierWave for image uploads. My images are uploading successfully, but when i click on an image, it does not give the lightbox effect. All i get is an enlarged thumbnail of the image.

This is my image_uploader.rb code in app/uploaders:

class ImageUploader < CarrierWave::Uploader::Base
 include CarrierWave::MiniMagick
 storage :file

 def store_dir
   "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
 end

 version :thumb do
    process :resize_to_limit => [350, 260]
 end

 def extension_white_list
    %w(jpg jpeg gif png)
 end
end

Solution

  • Maybe i'm too late, but try this: put <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> just before closing body tag. It helped me with the same issue.