2010-07-12 37 views
0

我們目前正在升級我們的rails版本,並且在我的一個date_select標記中遇到了一些奇怪的錯誤。date_select標記從2.1.2升級到2.3.8時

這裏是罪魁禍首:

<%= date_select :consultant_assignment, :start_date, :order => [:day, :month, :year], 
:start_year => 5.years.ago.year, :end_year => 5.years.from_now.year, :use_short_month => true %> 

此拋出這樣的錯誤:

NoMethodError在配置文件#顯示

顯示應用程序/視圖/人/ _upcoming_assignments.html.erb哪裏第46行提出:

你有沒有對象,當你沒有想到它! 您可能預期了Array的一個實例。而評估nil.size發生 錯誤

提取的源(左右線#46):

43:   <label for="consultant_assignment_start_date"><%= _('Start') %>:</label> 
44:   <% debugger %> 
45:   
46:   <%= date_select :consultant_assignment, :start_date, :order => [:day, :month, :year], :start_year => 5.years.ago.year, :end_year => 5.years.from_now.year, :use_short_month => true %> 
47:   
48:   
49:   

我試圖追查這個問題,似乎當我把在生成錯誤: month數組中的月份選項。所以當我這樣做時:order => [:day,:year]頁面加載完美。

我已經搜索了確切的問題,但更多的是前端deisgner,我不知道如何處理這一點。這是我的代碼錯誤?或者這是一個不贊成的方法?

這裏是application trace

/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:746:in `_unmemoized_month_names' 
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/memoizable.rb:72:in `month_names' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:781:in `month_name' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:708:in `select_month' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:705:in `upto' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:705:in `select_month' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:898:in `send' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:898:in `build_selects_from_types' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:896:in `each' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:896:in `build_selects_from_types' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:646:in `select_date' 
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_view/helpers/date_helper.rb:920:in `to_date_select_tag_without_error_wrapping' 

我用Google搜索有關unmemoized月份名稱,但我發現錯了。

好吧,我已經嘗試拿出整個:order子句只是爲了使事情工作。這一次它不會拋出錯誤,但標籤不會出現!我試着檢查irb,顯然我的date_select標記沒有返回任何選擇標記,而只是一堆隱藏的標記!

我試圖與默認軌道例如:

date_select("post", "written_on") 

IRB返回此:

=> 「\ n \ n \ n」 個

,你可以看到,沒有選擇標籤任何地方。我嘗試過datetime_select,並在那裏看到一個選擇標籤。那麼2.3.8的date_select有什麼優勢呢?

+0

適用於me.check您的日期從數據庫wheather是否正確也參考http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M002264 – Salil 2010-07-12 07:29:11

+0

我試着看着這個,仍然徒勞無功。我試着看看rails的新i18n的東西,並做了config/locale/en.yml和config/initializers/locale.yml,我仍然得到相同的錯誤 – corroded 2010-07-12 09:06:37

回答

0

看來這是i18n的問題,因爲rails無法看到由於某種原因聲明的月份名稱(應該看到它,因爲默認的lang是en)。實際上出於某種原因,它沒有看到默認語言。無論如何,我們現在的快速解決方案是在constants.rb中添加一個MONTH_NAMES常量並將其添加到date_select中的選項中。

0

使用這些格式

date_select(對象,方法,選項= {},html_options = {})

放START_YEAR,END_YEAR,order_field等的選項標籤內。

我認爲這可能會幫助你。

這些選擇準備用於對活動記錄對象進行多參數分配。

注意:如果不包括該日期作爲選項,但該月份是,則該日期將設置爲第1天,以確保所有月份選擇均有效。

+0

它仍然顯示相同的錯誤。我不認爲格式是問題,因爲它工作時,我拿出:月份選項,對吧? – corroded 2010-07-12 07:16:46

+0

某些時間格式會產生問題 請通過此鏈接它可能會幫助您。 http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html – 2010-07-12 08:00:33

+0

這是相同的鏈接Salil給了我2天前,我沒有找到任何東西:( – corroded 2010-07-14 08:46:18

相關問題