代码之家  ›  专栏  ›  技术社区  ›  corroded

日期\从2.1.2升级到2.3.8时选择标签

  •  0
  • corroded  · 技术社区  · 16 年前

    我们目前正在升级我们的Rails版本,我在一个日期选择标签中遇到了一些奇怪的错误。

    罪魁祸首是:

        <%= 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 在配置文件中显示

    显示app/views/people/u即将到来的_assignments.html.erb,其中第46行出现:

    当你没有预料到它的时候,你就没有了! 可能需要数组的实例。 计算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'
    

    我在谷歌上搜索了一些未被删除的月份名称,但我找到了娜达。

    好吧,我试着去掉了全部的:命令条款,只是为了让该死的东西工作。这次它不会抛出错误,但不会显示标签!我试过签入IRB,显然我的日期选择标签没有返回任何选择标签,只是一堆隐藏的标签!

    我用默认的Rails示例尝试了这个方法:

    date_select("post", "written_on")
    

    IRB返回:

    = \\gt;\\n\n\n

    如您所见,任何地方都没有选择标记。我尝试了datetime_select,在那里看到了一个select标记。那么2.3.8的日期选择是什么?

    2 回复  |  直到 15 年前
        1
  •  0
  •   Sachin R    16 年前

    使用这些格式

    日期选择(对象名称,方法,选项,html)

    在选项标签中输入开始年份、结束年份、订单字段等。

    我想这可能对你有帮助。

    选择是为活动记录对象的多参数分配而准备的。

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

        2
  •  0
  •   corroded    15 年前

    似乎i18n有问题,因为Rails由于某种原因看不到声明的月份名称(因为默认语言是en,所以应该可以看到)。实际上,由于某种原因,它看不到默认语言。不管怎样,我们现在的快速修复方法是在constants.rb中添加一个月名常量,并将其添加到日期选择中的选项中。

    推荐文章