从2.1.2升级到2.3.8时的date_select标记

时间:2010-07-12 06:09:29

标签: ruby-on-rails erb helpers actionpack

我们目前正在升级我们的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#show

显示第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 =&gt; [: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'

我已经搜索了未记忆的月份名称,但我找到了nada。

好吧,我已经尝试取出整个:order order子句,只是为了使这个糟糕的事情发挥作用。这次它不会抛出错误,但标签不会出现!我试过检查irb,显然我的date_select标签没有返回任何选择标签,只是一堆隐藏的标签!

我用默认的rails示例尝试了这个:

date_select("post", "written_on")

irb返回:

=&GT; “\ n \ n \ n” 个

如您所见,任何地方都没有选择标签。我尝试了datetime_select,然后在那里看到一个select标签。那么与2.3.8的date_select有什么关系?

2 个答案:

答案 0 :(得分:0)

使用这些格式

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

在选项标签中输入start_year,end_year,order_field等。

我认为这可能会对你有所帮助。

选择是为多参数分配到Active Record对象而准备的。

注意:如果日期不包含在选项中,但是月份是,则将日期设置为1,以确保所有月份选择都有效。

答案 1 :(得分:0)