我在簡單的表單做了一個表格此行保存值:的Rails不能從單選按鈕
<fieldset>
<legend>Any acessory?</legend>
<li><%= f.input :has_acessory, label: false, collection: ["0","1"], as: :radio_buttons, input_html:{ name: 'has_acessory'} %></li>
</fieldset>
和簡單的表單生成驗證碼:
<fieldset>
<legend>Any Acessory?</legend>
<li><div class="input radio_buttons optional lending_has_acessory"><label class="radio"><input checked="checked" class="radio_buttons optional" id="lending_has_acessory_0" name="has_acessory" type="radio" value="0" />0</label><label class="radio"><input class="radio_buttons optional" id="lending_has_acessory_1" name="has_acessory" type="radio" value="1" />1</label></div></li>
</fieldset>
我使用的SQLite3 ,這裏有一個名爲lendings的表,其中有一個名爲has_acessory的整數列,它的默認值是:0
In Lending model:
class Lending < ActiveRecord::Base
attr_accessible :devolution_date, :lending_date, :situation, :description,:has_acessory, :person_id, :equipment_id
#Associations
belongs_to :equipment
belongs_to :person
末
但它並不重要的價值,我的單選按鈕選擇,我總是得到「0」(默認值)column.I已經檢查了PARAMS的has_acessory,和我可以找到「has_acessory」=>「0」或「1」。
對我來說這部分工作得很好,但爲什麼不能將它保存在has_acessory列中?
當我嘗試只是<%= f.input:has_acessory%>,我可以發現我的問題是在input_html:{name:'has_acessory'}。當我刪除這條指令時,簡單的表單生成name =「lending [has_acessory]「,它工作。感謝你們! –