1

Trying to figure out how to use haml "link_to" with Ruby code in order to make an image on a page link to another page on the site. If possible I'd like to keep the nav static and fade the two pages in and out via a "Forward" and "Back" image. Any ideas? Just want to get the linking right first and then can go in and figure out the JQuery. Currently have the code below...

Thanks!!

    .pad-bottom50
    %div{:style => "position: absolute; top: 620px; left: 830px;"}
        =link_to (image_tag(@page.photos[1].image_url(:full), :id => "#fade1", :class => "animated") if @page.photos[1].image? 
    .pad-top20  
4

3 回答 3

4

link_to 的语法是

=link_to link_text, link_url, options

你错过了link_url。IE。单击图像时应将用户带到的位置。

这是一个工作示例

=link_to(image_tag("http://goo.gl/FZUI3"), "http://en.wikipedia.org/wiki/Nyan_Cat", :id => "#fade1", :class => "animated")
于 2012-10-17T04:56:45.297 回答
1

您应该首先查看 link_to 标记的参数。您将了解这些参数以及您可以使用这些参数做什么。

检查此链接 api doc

您可以检查API Ruby on Rails中可用的方法的所有参数

于 2012-10-18T07:24:01.023 回答
1

您没有为链接指定 src。语法是:

link_to "Link Text", "/path-to-link"

要在其中放置图像:

image_tag "path-to-image"
link_to(image_tag("path-to-image"), "/path-to-link")

如果 @page.photos[1].image?

link_to(image_tag(image_tag(@page.photos[1].image_url(:full), :id => "#fade1", :class => "animated")), "/bacon", :id => "bacon", :class => "bacon") if @page.photos[1].image?
于 2012-10-17T04:47:03.613 回答