简体   繁体   English

colorbox-rails gem — Lightbox会打开整个页面,而不仅仅是照片。 我该如何解决

[英]colorbox-rails gem — Lightbox is opening entire page, not just photo. How can I fix

I am using the colorbox-rails gem to implement a lightbox for a photo gallery. 我正在使用colorbox-rails gem为照片库实现灯箱。 Here's the documentation for the plugin -- http://www.jacklmoore.com/colorbox/ 这是该插件的文档-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. 当我单击照片的链接时,colorbox会在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". 因此,您正在调用的URL可能类似于“ 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"> . 通过浏览器检查页面源,以查看是否有一行类似于<a data-colorbox="true" href="/photos/1">

What you want to be targeting is likely "photo.image.url". 您想要定位的可能是“ 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? 因此,也许<%= link_to (image_tag photo.image.url(:medium)), photo.image.url, rel: 'photos', data: { colorbox_static: true } %>可能会成功?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM