簡體   English   中英

從2.1.2升級到2.3.8時的date_select標簽

[英]date_select tag when upgrading from 2.1.2 to 2.3.8

我們目前正在升級Rails版本,並且在我的date_select標記之一中遇到了一些奇怪的錯誤。

罪魁禍首:

    <%= 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 %>

這樣會拋出如下錯誤:

Profiles#show中的NoMethodError

在第46行出現的地方顯示app / views / people / _upcoming_assignments.html.erb:

當您沒有想到的時候,您有一個零對象! 您可能期望使用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:           

我試圖跟蹤此問題,並且當我在:order數組中放入:month選項時,似乎會生成錯誤。 因此,當我執行:order => [:day,:year]時,頁面會完美加載。

我已經搜索了確切的問題,但更多地是前端設計人員,我不確定如何進行此操作。 根據我的代碼,這是錯誤嗎? 還是不贊成使用的方法?

這是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搜索未記憶的月份名稱,但發現了nada。

好的,我嘗試刪除整個:order子句只是為了使該死的東西起作用。 這次它沒有引發錯誤,但是標簽沒有出現! 我嘗試簽入irb,顯然我的date_select標簽沒有返回任何選擇標簽,而只是返回了一堆隱藏標簽!

我嘗試使用默認的rails示例:

date_select("post", "written_on")

irb返回以下內容:

=>“ \\ n \\ n \\ n”

如您所見,在任何地方都沒有select標簽。 我嘗試使用datetime_select,並且在其中看到一個選擇標記。 那么2.3.8的date_select有什么用呢?

使用這些格式

date_select(object_name,method,options = {},html_options = {})

將start_year,end_year,order_field等放入options標記中。

我認為這可能對您有幫助。

准備將選擇內容分配給Active Record對象。

注意:如果不包括日期,而是包括月份,則將日期設置為第一天,以確保所有月份選擇均有效。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM