在link_to块中放置属性的位置

时间:2013-09-14 18:59:47

标签: ruby-on-rails

我正在尝试将标题放在html_options as described in the docs:

link_to shop_path(@shop, html_options = {title: "Hola el mundo") do
    content_tag( :span, "Hello", class: "some_class") + " " +
    content_tag( :span, truncate(@shop.name, length: 37))
end

但它不起作用。我在哪里将title属性放在link_to块中?

1 个答案:

答案 0 :(得分:3)

HTML属性可以作为link_to的选项传递,而不是像_path助手一样传递:

link_to shop_path(@shop), title: "Hola el mundo" do
  content_tag( :span, "Hello", class: "some_class") + " " +
  content_tag( :span, truncate(@shop.name, length: 37))
end