我們目前正在升級我們的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有什麼優勢呢?
適用於me.check您的日期從數據庫wheather是否正確也參考http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M002264 – Salil 2010-07-12 07:29:11
我試着看着這個,仍然徒勞無功。我試着看看rails的新i18n的東西,並做了config/locale/en.yml和config/initializers/locale.yml,我仍然得到相同的錯誤 – corroded 2010-07-12 09:06:37