简体   繁体   中英

Can't display sign '-' with rails enumerize

I am using enumerize in my rails app. In model/user :

enumerize :ranking, in: ['- 2/6', '- 4/6', '- 15', '- 30']

in my views I have user/edit.html.erb I have

<%= simple_form_for(@user)  do |f| %>
   <%= f.input :ranking, label: "Classement" %>

...

The problem is only in the option list on select : when the option is actually selected and the form submitted. It displays nicely the minus sign in user/show The generated html for the select is as follows

<option value="- 2/6"> 2/6</option>
<option value="- 4/6"> 4/6</option>
<option value="- 15"> 15</option>

so the value is right but not the text inside the tags

It displays the select options but the "-" sign that precedes all ranking doesnt display. How can I fix that ?

I found the answer to my own problem. If you go check the gem running

bundle show enumerize 

in your console. You will find in scope / value.rb file :

def i18n_keys
 i18n_keys << self.underscore.humanize # humanize value if there are no translations
end

When the translation of the given value is not defined in the I18N file, enumerize runs the methods underscore and humanize on the string. So I actually solved the problem by updating my I18n file with all my rankings values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM