I am using the colorbox-rails
gem to implement a lightbox for a photo gallery. Here's the documentation for the plugin -- http://www.jacklmoore.com/colorbox/
Here is how I am iterating over the photos in the view:
<div id="photos">
<% @photos.each do |photo| %>
<%= link_to (image_tag photo.image.url(:medium)), photo, rel: 'photos', data: { colorbox_static: true } %>
<% end %>
</div>
When I click on the link of the photo, colorbox opens the entire webpage in the lightbox. I would, of course, only like the photo to be in the lightbox.
I've tried stubbing out the path to the photo, but that didn't work.
Thanks for your time.
Although I don't have complete information, it looks like you are targeting the link on "photo" which appears to be the model. So you are calling a url that might be something like "photos/1". Check the page source via your browser to see if you have a line that looks like <a data-colorbox="true" href="/photos/1">
.
What you want to be targeting is likely "photo.image.url". which would make the target the actual photo rather than the web page where the photo resides. So perhaps <%= link_to (image_tag photo.image.url(:medium)), photo.image.url, rel: 'photos', data: { colorbox_static: true } %>
might do the trick?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.