2017-03-12 23 views
0

我試圖用simple_form到顯示模型的值(而不是輸入它們)。對於我belongs_to協會,我只是想用一個字符串:一個正常的只讀輸入字段中描述屬性。我希望有一個選擇下拉在這種情況下,因爲我只顯示值。我試着像simple_form:belongs_to的作爲字符串輸入字段

<%= f.association :matrix, 
     label_method: :description, 
     as: :string, 
     readonly: true %> 

哪個使字段只讀輸入,而是把協會的只是ID(在這種情況下,matrix_id),而不是:描述( my_object.matrix.description)字段。

我缺少什麼?請幫忙。

回答

1

Simple_form不是爲這種行爲作出。

只需插入下面的領域,因爲我們不希望它在更新行動派:

<input type="text" value="<%= f.object.matrix.description if f.object.matrix %>" readonly> 
+0

嗯,這就是我所擔心的。謝謝! – istrasci

相關問題