简体   繁体   English

不能用滑轨枚举显示符号“-”

[英]Can't display sign '-' with rails enumerize

I am using enumerize in my rails app. 我在Rails应用程序中使用了枚举。 In model/user : 在模型/用户中:

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

in my views I have user/edit.html.erb I have 在我看来,我有user / edit.html.erb

<%= 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. 问题仅在select的选项列表中:当实际选择了选项并提交了表单时。 It displays nicely the minus sign in user/show The generated html for the select is as follows 它很好地显示了user / show中的减号。select的生成的html如下

<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 : 您将在scope / value.rb文件中找到:

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. 如果在I18N文件中未定义给定值的转换,则enumerize在字符串上运行下划线和人性化方法。 So I actually solved the problem by updating my I18n file with all my rankings values. 因此,我实际上通过使用所有rankings值更新I18n文件来解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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