2010-07-12 122 views
0

我们目前正在升级我们的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有什么优势呢?

+0

适用于me.check您的日期从数据库wheather是否正确也参考http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M002264 – Salil 2010-07-12 07:29:11

+0

我试着看着这个,仍然徒劳无功。我试着看看rails的新i18n的东西,并做了config/locale/en.yml和config/initializers/locale.yml,我仍然得到相同的错误 – corroded 2010-07-12 09:06:37

回答

0

看来这是i18n的问题,因为rails无法看到由于某种原因声明的月份名称(应该看到它,因为默认的lang是en)。实际上出于某种原因,它没有看到默认语言。无论如何,我们现在的快速解决方案是在constants.rb中添加一个MONTH_NAMES常量并将其添加到date_select中的选项中。

0

使用这些格式

date_select(对象,方法,选项= {},html_options = {})

放START_YEAR,END_YEAR,order_field等的选项标签内。

我认为这可能会帮助你。

这些选择准备用于对活动记录对象进行多参数分配。

注意:如果不包括该日期作为选项,但该月份是,则该日期将设置为第1天,以确保所有月份选择均有效。

+0

它仍然显示相同的错误。我不认为格式是问题,因为它工作时,我拿出:月份选项,对吧? – corroded 2010-07-12 07:16:46

+0

某些时间格式会产生问题 请通过此链接它可能会帮助您。 http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html – 2010-07-12 08:00:33

+0

这是相同的链接Salil给了我2天前,我没有找到任何东西:( – corroded 2010-07-14 08:46:18