Forum: Ruby on Rails Right way to do

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-01-27 19:46
What is the right way to print localizations?

<%=t :User %> OR <%=t "User" %> OR <%=t ("User") %>

<%=t :User %> works fine, but <%=t :User.Username %> doesn't, but this
works:
<%=t ("User.Username") %>
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-01-28 02:02
(Received via mailing list)
> What is the right way to print localizations?
>
> <%=t :User %> OR <%=t "User" %> OR <%=t ("User") %>
>
> <%=t :User %> works fine, but <%=t :User.Username %> doesn't, but this
> works:
> <%=t ("User.Username") %>

I'd go with <%=t "User" %>.

:User works in this case because t() is converting the argument to a
string and :User.to_s => "User".  :User.Username won't work because
there is no "Username" method on the *symbol* "User".

-philip
This topic is locked and can not be replied to.