ruby-on-rails – 如何使用带有Draper gem的i18n翻译方法?
发布时间:2020-12-17 04:05:27 所属栏目:百科 来源:网络整理
导读:我使用Draper gem来装饰我的模型.在这里,我有非常经典的设置: # app/decorators/subject_decorator.rbclass SubjectDecorator ApplicationDecorator decorates :subject def edit_link h.link_to(h.t('.edit'),'#') endend 我使用i18n进行国际化.但是当我运
我使用Draper gem来装饰我的模型.在这里,我有非常经典的设置:
# app/decorators/subject_decorator.rb class SubjectDecorator < ApplicationDecorator decorates :subject def edit_link h.link_to(h.t('.edit'),'#') end end 我使用i18n进行国际化.但是当我运行这个时,我得到: Cannot use t(".edit") shortcut because path is not available 所以我想知道以前是否有人这样做过?它应该很直接. 解决方法
在您的代码中,您必须使用:
I18n.t('mylabelkey') 试一试……应该有用 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |