翻译activetraord集合以获取下拉列表
在模型中我有一些状态
STATES = ["in_progress", "active", "archived"]
在我的表格中,我想要一个下拉/选择
In Progress, Active, Archived for english
和
ชำระ , ขัน , ยื่น in Thai
处理这个问题的最佳方法是什么?
我想到的一个选择如下
def self.states @states = {} STATES.each do |s| @states[s] = I18n.t(s) end @states end
有没有更好的办法?
这由simple_form支持:
在您看来,您应该使用
<%= f.input :state, collection: ["in_progress", "active", "archived"] %>
在你的yaml文件中,你应该有
simple_form: options: defaults: state: in_progress: In progress active: Active archived: Archived