Ruby on Rails - 在包含I18n的link_to调用中嵌入了额外的HTML [英] Ruby on Rails - embed additional HTML inside of link_to call that includes I18n

查看:171
本文介绍了Ruby on Rails - 在包含I18n的link_to调用中嵌入了额外的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在此线程中找到的link_to调用中嵌入其他HTML 在link_to调用中嵌入其他HTML

I am trying to embed additional HTML inside of a link_to call as found in this thread Embed additional HTML inside of link_to call

但是,我还想使用I18n。所以不是这样:

However, I would also like to use I18n. So instead of this:

 <%= link_to '<i class="icon-search"></i> Show'.html_safe, exercise_path(exercise), :class => 'btn btn-small' %>

我想使用 t(:show) I18n.t(:show)而不是上面示例中的硬编码显示。但是,我无法弄清楚正确的语法。任何帮助将不胜感激。

I would like to use t(:show) or I18n.t(:show) instead of a hardcoded Show in the above example. I am having trouble figuring out the correct syntax, though. Any help would be greatly appreciated.

推荐答案

有一种更简单/更清洁的方式将其他项目嵌入 link_to 使用其块语法。 E.x。

There's an easier/cleaner way to embed additional items into a link_to by using its block syntax. E.x.

<%= link_to exercise_path(exercise), :class => 'btn btn-small' do %>
  <i class="icon-search"></i>
  <%= t(:show).html_safe %>
<% end %>

这篇关于Ruby on Rails - 在包含I18n的link_to调用中嵌入了额外的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆