put haml tags inside link_to helper

馋奶兔 提交于 2019-11-28 18:08:57

You should use block

= link_to "path/to/page.html" do
  Other page
  %span.icon Arrow
Paul

If anyone is still using Rails 2.x on a project, it looks like the accepted answer returns the block, thus duplicating the link in the markup. Very simple change: use - instead of =

- link_to "path/to/page.html" do
  Other page
  %span.icon Arrow

The simplest way to do it is by using html_safe or raw functions

= link_to 'Other Page<span class="icon"></span>'.html_safe, "path/to/page.html"

or using raw function (recommended)

= link_to raw('Other Page<span class="icon"></span>'), "path/to/page.html"

Simple as it can get !!

Don’t use html_safe method unless you’re sure your string isn’t nil. Instead use the raw() method, which wont raise an exception on nil.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!