2011-03-30 70 views
0

我有兩個關於simple_form rails gem的問題。rails simple_form位掩碼屬性

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. 我怎麼能顯示與掩碼屬性複選框? (布魯斯位掩碼)

回答

0
  1. f.input :attribute, :collection => YourModel::OPTIONS.collect
  2. f.input :roles, :as => :check_boxes, :collection => User.roles.collect
2

1)simple_form supports I18n for options。你只是通過符號的陣列和翻譯將被查找如下:

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,翻譯如上