如何从 Rails 中的一张图像获得多个链接
我有一张图像,根据单击的图像部分,我必须从中获得 7 个不同的链接。我该如何使用 Rails 来实现它?
I have one image from which I have to have 7 different links based on the part of the image clicked. How do I go about it using rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了将来的参考,你正在谈论“图像映射” - 有各种教程,例如
http:// /www.onextrapixel.com/2009/04/30/how-to-create-multiple-links-on-a-single-image-with-image-map/
据我所知这不是这确实是一个 Rails 问题,因为图像映射完全是前端的东西:像 js 一样,它们只与浏览器中看到的页面相关。就 Rails 而言,当您单击链接时,它并不关心该链接是否在图像地图上。
因此,这只是您放入视图模板中的一些原始 html。
我想您可以使图像地图数据驱动,例如您将图像文件名存储在数据库中,然后将任何地图数据也保存在数据库中的 image_maps 表中。仅当您想让图像映射可供用户编辑时才值得这样做,例如闪烁。 (flickr 允许您在现有照片上绘制一个矩形并用一些文本标记它)
For future reference, you're talking about "image maps" - there's various tutorials for these, eg
http://www.onextrapixel.com/2009/04/30/how-to-create-multiple-links-on-a-single-image-with-image-map/
As far as i know this isn't really a rails question, as image maps are a totally front-end thing: like js, they only relate to the page as seen in the browser. As far as rails is concerned, when you click on a link it doesn't care whether that link was on an image map or not.
So, it's just some raw html that you would put in your view template.
I suppose you could make the image maps data-driven though, so that for example you store an image filename in the db and then save any map data in the db too, in an image_maps table. It's only worth doing this if you want to make the image maps user-editable, like flicker does for example. (flickr lets you draw a rectangle on an existing photo and tag it with some text)
只需使用 url_for 生成所需的 url,
root_path 定义为主页,resource1 定义为 config/routes.rb 中的资源。
just use url_for to generate the needed url
the root_path is defined as the home page and resource1 as a resource in config/routes.rb.
这更多的是 javascript/flash 类型的事情。如果您确切知道链接需要去哪里,并且您不是在寻找供用户单击的区域,那么您绝对可以定位带有链接的 div,因为这只会在特定位置生成带有文本的链接。
听起来你需要制作一个 Flash 应用程序或执行 JavaScript 解决方法。这不是 Rails 类型问题,因此您的解决方案不会来自 Ruby/Rails。
This is more of a javascript/flash type thing. You can absolutely position divs with links if you know exactly where the links need to go and you are not looking for an area for the user to click because this will just generate a link with text in a specific position.
Sounds to mee like you will need to make a flash app or do javascript workaround. This is not a Rails type issue so your solution won't come from Ruby/Rails.