2012-09-06 26 views
0

我在填充date值從我的數據庫到Rails View對象有問題。我在數據庫中有一個表License,其屬性爲license_expiration="2012-11-11"。當用戶選擇「編輯」時,我需要在View中填充此值。我有在edit.html.erb文件是:date_select ruby​​問題,同時填充'視圖'中的db值

<h1>Edit License</h1> 
<% product_options_for_selector = options_for_select(product_selection_options, 
@license.product ? @license.product.id : product_selection_options.first.last) 
%> 

<% form_tag("/licenses/#{@license.id}", :method => :put, :id => "edit_license_#  @license.id}") do %> 
. 
. 
. 
. 
<%= label_tag :license_expiration, 'License Expiration:' %> <br /> 
<%= date_select :license_expiration, @license.license_expiration %> 
. 
. 
. 

然而,date_select始終默認爲當前日期,而不是從DB的@license.license_expiration值。有什麼想法,我在做什麼錯在這裏?幫助,將不勝感激,

謝謝,

--- J.A.N.

回答

0

你試過嗎?

<%= date_select :license_expiration, :license_expiration, :default => Time.parse(@license.license_expiration) %> 
+0

感謝您對Antoine的迴應,非常感謝。 – user1653279

+0

這意味着基本上,我需要使用「默認」選項來獲取'日期'。爲什麼正則表達式不起作用?我是一個紅寶石/鐵路新手,所以想要更好地理解它。謝謝, – user1653279

+0

其他評論沒有通過。我嘗試了你的解決方案,但那沒有奏效。它在分析過程中生成了一個「NoMethodError」,出現以下異常:「未定義的方法'gsub!'對於2012年10月19日星期五:日期「但是,當我從相同的時間刪除'Time.parse'時,一切似乎都正常。我能夠從數據庫正確檢索「日期」到「查看」頁面。謝謝, – user1653279