Can you change label display names when using simple-form in rails?

SlowBucket picture SlowBucket · Dec 2, 2012 · Viewed 14.2k times · Source

I am using simple-form in rails and I would like to know if there is a way to change the way collection objects are displayed. For example I have something like this

<%= f.input :lang, :label => "Language", :collection => [ "en", "es, "zh", "fr" ] %>

Instead of showing up as "en es zh" etc I would like it to show up as "English Spanish" etc to the user. Is there anyway to do that sort of thing?

Thanks in advance.

Answer

user1193139 picture user1193139 · Dec 2, 2012

You can use following way as well:

In Model:

    LANGUAGES = {'English' => 'en','French' => 'fr'}

In View:

    <%= f.input :lang, :label => "Language", :collection => Model::LANGUAGES %>