0
於是我在ROR一個初學者,就像我知道這一個月(學校分配和我們沒有得到我們需要使用「谷歌」一的cursus)Ruby on Rails的下拉框中初學者拉特
所以我想要一個包含我所有城市列表的下拉框。然後,如果我選擇一個城市,我需要將city_id與日期一起保存在我的數據庫中。該代碼我迄今似乎只是當我點擊上班保存它說,城市是空的(並且由於failsave它不能爲空)
這是我的代碼
<div class="field">
<%= f.label :stad_id %><br />
<% cities_array = Stad.all.map { |stad| [stad.naam, stad.land] } %>
<%= select_tag(Stad, options_for_select(cities_array)) %>
</div>
<div class="field">
<%= f.label :datum %><br />
<% datum = Time.now.to_s(:db) %>
<%= f.text_field :datum, :value => datum.inspect, :readonly => true %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我我真的不知道我在做什麼錯,除非我有一種痛苦的感覺,我實際上並沒有給出命令來保存它。
的幫助是非常感謝 真誠 羅賓
它有點兒,但是當我把這個數組放在controllere中。 'code'@ cities_array = Stad.all.map {| stad | [stad.naam,stad.id]}'code',我的表單現在看起來像這樣。 'code'
<%= select :stad_naam, :stad_id, @cities_array %>