2014-02-15 19 views
1

我想在Customer::ROLES阵列应用国际化上,如何在选择适用国际化的视图页面

价值在客户::职责分工general, vip, platinum阵列

但我有错误,当我在此把它包方式t(Customer::ROLES , scope: 'CUSTOMER')

= f.input :role,label: t("role"),as: :select, | 
:collection => Customer::ROLES, | 
:selected => 1 

这里的YML文件

CUSTOMER: 
    platinum: "白金" 
    vip: "vip" 

这里的错误信息

NoMethodError in Customers#edit 

undefined method `to_a' for #<ActiveSupport::SafeBuffer:0x007fe0e76b6e88> 

回答

0

像这样ü可以设定I18值

<%= I18n.t 'CUSTOMER.platinum'%> 
+0

你不明白的问题,我想申请转换数组对象。 – newBike

+0

你不能这样做。 –

0

我不知道是否Rails的普遍支持这一点,但simple_form当然不会:

f.input :role, collection: [...] 

将尝试翻译给定集合数组中的元素。它看起来在.yaml文件类似

simple_form: 
    options: 
    customer: 
     role: 
     platinum: ... 
     vip: ... 

(见https://github.com/plataformatec/simple_form