Wednesday, November 23, 2011

Re: [Rails] Re: Scaffold and Localize

2011/11/22 Paul Bergstrom <lists@ruby-forum.com>:
> Norbert Melzer 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.

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate