Scaffold and Localize

Is there a way to translate the labels in a scaffold?

Using <%= f.label :lastname %> instead of having to change that to
<%= t(:lastname) %>

2011/11/22 Paul B. [email protected]:

Using <%= f.label :lastname %> instead of having to change that to
<%= t(:firstname) %>

Cant test it straight away, but

f.label(t(:whatever))

should do the trick

Norbert M. wrote in post #1033193:

Cant test it straight away, but

f.label(t(:whatever))

should do the trick

Thanks.

Would be great if the possibility to localize could be built-in directly
in scaffold.

2011/11/22 Paul B. [email protected]:

in scaffold.
After some more research, it is!

Given a Model “User” with the attribute “name”

some view with a form in it:
form_for @user do |f|
f.label :name
end

this will create a label for the input field with id :name AND label
this according to the result that “User.human_attribute_name(:name)”
would give.

just see label as an alias for

f.label :name, @user.class.human_attribute_name(:name)

Put in your locale then this structure:

en:
activerecord:
attributes:
user:
name: “The word your mother says when refering to you”

I stumbled upon this during my research. I wanted to create scaffold
generators that do I18n. Here is the URL to the guides:

http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models

HTH
Norbert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs