0

我有两个关于 simple_form rails gem 的问题。

1.

有没有更好的方法来自动从输入集合中的模型转换静态数组?

OPTIONS = [:val1,:val2,:val3] #constant from my model:
#for now i'm doing this:        
f.collection_radio :model_attribute, MyModel::OPTIONS .collect { |o| [t(o, :scope=>[:activerecord, :attributes, :MyModel]), "#{o}"] }, :last, :first %>
  1. 我如何用复选框显示位掩码属性?(布鲁斯位掩码)

4

2 回答 2

2

1) simple_form 支持 I18n 选项。您只需传递一个符号数组,就会按如下方式查找翻译:

en:
  simple_form:
    options:
      model:
        model_attribute:
          val1: 'Value 1'
          val2: 'Value 2'
          val3: 'Value 3'

2) f.input :roles, :as => :check_boxes, :collection => User.values_for_roles, 翻译如上

于 2012-06-06T17:07:49.620 回答
0
  1. f.input :attribute, :collection => YourModel::OPTIONS.collect
  2. f.input :roles, :as => :check_boxes, :collection => User.roles.collect
于 2011-03-30T10:01:36.613 回答