【发布时间】:2010-07-12 06:09:29
【问题描述】:
我们目前正在升级我们的 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 %>
这会抛出如下错误:
NoMethodError in Profiles#show
显示第 46 行出现的 app/views/people/_upcoming_assignments.html.erb:
当你没想到时,你有一个 nil 对象! 您可能期望有一个 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'
我在谷歌上搜索了未记忆的月份名称,但我找到了 nada。
好的,我已经尝试删除整个 :order 子句,只是为了让这该死的东西正常工作。这次它没有抛出错误,但标签没有出现!我尝试签入 irb,显然我的 date_select 标签没有返回任何选择标签,而只是一堆隐藏标签!
我用默认的 rails 示例尝试了这个:
date_select("post", "written_on")
irb 返回:
=> "\n\n\n"
如您所见,任何地方都没有选择标签。我尝试了 datetime_select ,我在那里看到了一个选择标签。那么 2.3.8 的 date_select 是怎么回事呢?
【问题讨论】:
-
为我工作。从数据库中检查你的日期是否正确也参考api.rubyonrails.org/classes/ActionView/Helpers/…
-
我试过看这个,但仍然无济于事。我尝试查看 rails 的新 i18n 东西并制作了 config/locale/en.yml 和 config/initializers/locale.yml,但我仍然遇到同样的错误
标签: ruby-on-rails erb helpers actionpack