在Rails中添加span标签link_to
我已经看过有关如何添加 标签的信息,但我没有看到将
放置在我想要使用 Rails 的位置的示例3
link_to
:
<a href="#" class="button white"><span id="span">My span </span>My data</a>
我尝试过类似的操作:
<%= link_to(content_tag{:span => "My span ", :id => "span"} @user.profile.my_data, "#", {:class => "button white"}) %>
但这没有用。
I've looked on SO about how to add a <span>
tag but I didn't see an example that placed the <span>
where I want using Rails 3 link_to
:
<a href="#" class="button white"><span id="span">My span </span>My data</a>
I tried something like:
<%= link_to(content_tag{:span => "My span ", :id => "span"} @user.profile.my_data, "#", {:class => "button white"}) %>
But that didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
link_to
可以占用一个块,所以我认为你正在追求这样的东西:link_to
can take a block so I think you're after something like this:.html_safe
与#{@user.profile.my_data}
的组合也应该有效。您还可以使用
content_tag
,这样它看起来就像:它们基本上是相同的,但其中一个可能对您来说更容易看到。另外,我对编码还很陌生,所以如果由于某些疯狂的原因这是完全错误的,请发表评论,我会更改它。谢谢。
A combination of the
.html_safe
with#{@user.profile.my_data}
should work as well.You can also use a
content_tag
so it would look like:They're basically identical but one might be easier on the eyes for you. Also, I'm pretty new to coding so if this is dead wrong for some crazy reason, please just comment and I'll change it. Thanks.
在 HAML 中:
In HAML :