在URL背面添加#gallery - 用于ruby脚本

时间:2012-10-11 22:54:23

标签: ruby-on-rails ruby

我有一张照片的红宝石脚本,其中包含指向其网址的链接:

<%= if property.images[0] then link_to image_tag (property.images[0].image.url('350x263', :jpg)), user_property_image_path(user, :id => property.images[0], :property_id => property) end -%>

如何将#gallery附加到网址末尾?

1 个答案:

答案 0 :(得分:2)

试试这个(为清晰起见分为多行):

link_to(
  image_tag(property.images[0].image.url('350x263', :jpg)),
  user_property_image_path(user,
    :id => property.images[0],
    :property_id => property,
    :anchor => "gallery"
  )
)

关键位是:anchor => "gallery"#url_for会识别此内容,并将其作为网址片段附加到网址。

有关可用选项的完整列表,请参阅documentation on url_for