uninitialized constant ActiveSupport::CoreExtensions

半世苍凉 提交于 2019-12-10 13:14:34

问题


I'm attempting to integrate jquery's datepicker with formtastic as detailed here

I've followed the directions exactly, but am getting "uninitialized constant ActiveSupport::CoreExtensions" when running this code:

<%= semantic_form_for @item, :html => { :multipart => true, :class => 'form'} do |f| %>
 <div class="group">
  <%= f.label :create_date, :class => 'label' %>
  <%= f.input :create_date, :as => :datepicker %>
 </div>
<% end %>

I attempted to put this in my config/application.rb:

require 'active_support/core_ext/date/conversions'

I've restarted the server but am still getting the same error. Am I putting this require line in the correct place?


回答1:


Checking the page you linked, I assume the problem is the following line:

format = options[:format] || ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default] || '%d %b %Y'

Looking at the file you mentioned, it appears that Rails now modifies the Date class directly rather than defining ActiveSupport::CoreExtensions::Date; furthermore, passing :default as the key to DATE_FORMATS appears to just call to_default_s on the object. The easiest way to deal with this would probably be to remove the whole reference to ActiveSupport::CoreExtensions, since the code also specifies a default:

format = options[:format] || '%d %b %Y'

You could also specify one of the date formats Rails adds in conversions.rb as so:

format = options[:format] || Date::DATE_FORMATS[:rfc822] || '%d %b %Y'


来源:https://stackoverflow.com/questions/5162395/uninitialized-constant-activesupportcoreextensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!