2014-06-12 42 views
0

以下:confirm弹出一个窗口,询问“删除记录?”:如何做:确认link_to在Rails 3.2中使用I18n.t()?

<%= link_to t('Delete'), misc_definition_path(@misc_definition), :method => :delete, :confirm => 'Delete the record?' 

如果添加I18n.t()的消息,但是确认窗口不弹出:

<%= link_to t('Delete'), misc_definition_path(@misc_definition), :method => :delete, :confirm => I18n.t('Delete the record?') 

尝试过“#{I18n.t()}”,无法正常工作。有没有一种方法可以让I18n.t的消息?谢谢。

+1

确实是关键的I18n存在?如果没有,我想它会渲染一些非常无效的HTML,以防止代码按预期工作。 – sevenseacat

+1

语法正常,所以它应该是你的密钥的东西。现在,一般来说,我推荐再次使用“删除记录?”之类的按键。我会采取像“messages.confirm_delete”作为关键... – Danny

+0

你们都是对的! yml没有关键。 – user938363

回答

4

语法无误。

 
Try this - 
Add some key in your config/locales/*.yml 
confirm_delete: 'Delete Record' 

使用此键原样

<%= link_to t('Delete'), misc_definition_path(@misc_definition), :method => :delete, :confirm => I18n.t('confirm_delete') %>

相关问题