如何从 Rails 中的一张图像获得多个链接

发布于 2024-10-10 08:41:59 字数 59 浏览 6 评论 0原文

我有一张图像,根据单击的图像部分,我必须从中获得 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝情姑娘 2024-10-17 08:41:59

为了将来的参考,你正在谈论“图像映射” - 有各种教程,例如
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)

人疚 2024-10-17 08:41:59

只需使用 url_for 生成所需的 url,

<img usemap="image_link" src="..." alt="" width="235" height="32" style="display: block;" />
<map name="image_link">
    <area href="<%= url_for root_path %>" alt="Home" coords="0,0,189,19" shape="rect" />
    <area href="<%= url_for :controller => "post", :action => "all" %>" alt="All posts" coords="190,0,386,22" shape="rect" />
    <area href="<%= url_for new_resource1_path %>" alt="New resource1" coords="387,0,657,23" shape="rect" />
</map>

root_path 定义为主页,resource1 定义为 config/routes.rb 中的资源。

just use url_for to generate the needed url

<img usemap="image_link" src="..." alt="" width="235" height="32" style="display: block;" />
<map name="image_link">
    <area href="<%= url_for root_path %>" alt="Home" coords="0,0,189,19" shape="rect" />
    <area href="<%= url_for :controller => "post", :action => "all" %>" alt="All posts" coords="190,0,386,22" shape="rect" />
    <area href="<%= url_for new_resource1_path %>" alt="New resource1" coords="387,0,657,23" shape="rect" />
</map>

the root_path is defined as the home page and resource1 as a resource in config/routes.rb.

疧_╮線 2024-10-17 08:41:59

这更多的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文