Ruby-on-rails 如何在 HAML 中制作此链接标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5838785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make this link tag in HAML?
提问by Meltemi
How can I do something like this in HAML (within Rails app such that it matters)?
我怎样才能在 HAML 中做这样的事情(在 Rails 应用程序中,这样很重要)?
<li><a href="#" title="Meet the Team"><strong>Team <em>16 members</em></strong></a></li>
Edit: how also to do it with link_toand a route of pages_team?
编辑:怎么也用link_to和一个路线来做pages_team?
采纳答案by Unixmonkey
%li= link_to raw('<strong>Team <em>16 members</em></strong>'), pages_team, :title => 'Meet the Team'
or
或者
%li= link_to content_tag(:strong, raw("Team #{content_tag(:em, '16 members)}")), pages_team, :title => 'Meet the Team
回答by radixhound
The basic method would look like this ...
基本方法看起来像这样......
%li
%a{ :href => "#", :title => "Meet the Team" }
%strong
Team
%em 16 members
Or using the new hash syntax ...
或者使用新的哈希语法......
%li
%a{ href: "#", title: "Meet the Team" }
%strong
Team
%em 16 members
回答by Tiago
I believe the best way to do this is:
我认为最好的方法是:
%li
= link_to "#" do
Meet the team
%strong
Team
%em 16 members
Using haml and rails syntax together
一起使用haml和rails语法
回答by user1196687
There is a very simple method available in Haml and Rails, here it is:
在 Haml 和 Rails 中有一个非常简单的方法,它是:
= link_to "hyperlink name", hyperlink_path

