如何在表单中使用gettext
?这不起作用:
<%= select f, :gender, [gettext "Male:": "male",
gettext "Female:": "female"], class: "form-control" %>
答案 0 :(得分:2)
您无法在关键字列表语法的关键部分调用函数,但您可以传递2个字符串的元组列表:
<%= select f, :gender, [{gettext("Male:"), "male"},
{gettext("Female:"), "female"}], class: "form-control" %>
值应该是包含两项元组的Enumerable(如常规列表或映射)或任何Enumerable,其中元素将用作生成的select的键和值。