Fancybox error in rails

旧城冷巷雨未停 提交于 2019-12-12 03:27:44

问题


I have been made a post model with picture upload and attached fancybox to display these pictures and this all works great.

Example:

<div id="pictures_in_form"><%= link_to image_tag(asset.object.image.url(:thumb)), asset.object.image.url(:big), :class => "fancybox", :rel => "gallery" if asset.object.image? %></div>

But when I want to attach a fancybox to a single image, I have error:

The requested content cannot be loaded.
Please try again later.

Example:

<%= link_to (image_tag 'about_school/par_livu_skolu_1.jpg'), '/about_school/par_livu_skolu_1.jpg', :class => "fancybox"%>

So can anyone point to the problem? Thank you!


回答1:


Try moving your opening parens like this:

<%= link_to (image_tag ('about_school/par_livu_skolu_1.jpg'), '/about_school/par_livu_skolu_1.jpg', :class => "fancybox") %>

That might fix it.




回答2:


The first image path starts without slash / like :

about_school/par_livu_skolu_1.jpg

... so it indicates a relative path. If the calling page, for instance, is located in a subdirectory like :

/mysubdir/page.html 

... then the image path will be

/mysubdir/about_school/par_livu_skolu_1.jpg

On the other hand, the second image path does start with slash / like :

/about_school/par_livu_skolu_1.jpg

...which means that the image path starts from root regardless where the calling page is located.

I guess you need to correct either path, whatever is correct otherwise fancybox won't find the image and will display the message

The requested content cannot be loaded.
Please try again later.


来源:https://stackoverflow.com/questions/15011694/fancybox-error-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!