2015-07-10 50 views
2

我有以下生成表單的行。被調用時,控制器在某些情況下將@disabled設置爲true,在其他情況下將false設置爲true。設置默認值:在窗體上禁用時,某些布爾選項被禁用?

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled }, url: wizard_path, method: :put do |f| 

在一些頁面上,我有一個使用布爾選項的select語句。

= f.input :accommodation, as: :select, collection: yes_no 

調用以下輔助函數的集合

def yes_no 
[ 
    ['Yes', true ], 
    ['No', false ] 
] 
end 

當@disabled設置爲false,並simple_form去渲染錯誤選項,似乎將其禁用。我不確定如何解決這個布爾型爭奪,以在下拉列表中生成true和false選項,同時還允許@disabled禁用整個表單(如果適用)

回答

0

SimpleForm和Rails之間的已知問題:https://github.com/plataformatec/simple_form/issues/1257

tonywok的答案似乎是目前一個有效的解決方法:https://github.com/plataformatec/simple_form/issues/1257#issuecomment-119226834

變化

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled }, url: wizard_path, method: :put do |f| 

= simple_form_for [:applicant, @application ],defaults: { disabled: @disabled, readonly: nil }, url: wizard_path, method: :put do |f| 
相關問題