如何将标签转换为link_to标签

时间:2013-10-07 06:43:57

标签: ruby-on-rails ruby

如何将以下Pinterest标记转换为rails link_to标记,以便我可以动态创建链接

<a href="//www.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest" data-pin-do="buttonPin" data-pin-config="none"></a>

1 个答案:

答案 0 :(得分:3)

url = "//www.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest"

link_to "Pinterest", url, { data: { pin_do: "buttonPin", pin_config: "none"} }

请注意,由于破折号,您需要在'pin-do'和'pin-config'周围加上引号。 更新:感谢@Stefan,我现在已经了解到Rails会自动将下划线转换为数据标记中的连字符。

<强>参考: