2016-02-04 49 views
0

我有an_errors.html.erb接受一個對象,具有如何設置使用.yml類的名稱在Rails的

<%= object.class.name %>. 

它是由這在_form.html.erb叫:

<%= render 'shared/errors', object: @product %> 

我應該在我的xx.yml文件中寫什麼來尋找翻譯?

models: 
    product: Produkt 

不勝任。

任何線索?

乾杯卡爾

回答

0

我對你所要經過不是很清楚,但是,下面可能會奏效。

在你的YAML文件:

models: 
    product: 'Product' 

在您的ERB觀點:

# The following assumes "object" in your original post relates to the string (Product) in the YAML file 
<%= object.constantize %> # this outputs the details of your class 
<%= object.constantize.to_s %> # would be a string representation of your class (i.e., 'Product') 

API docs for Constantize

再次,是不是100%肯定是你所希望實現的,但希望報價在它有幫助的情況下的建議!

+0

我做了一些澄清。 'object'是Product類的一個對象。 <%= object.class.name.constantize%>給我'產品',但不是我的翻譯版本。 – abegbg