【发布时间】:2010-10-24 09:17:23
【问题描述】:
所以我想做的是覆盖默认的 date_select 方法(我想做一个“可选/未指定”的日期输入)。到目前为止,我尝试过的是:
lib/overrides.rb
ActionView::Helpers::DateHelper::DateTimeSelector.class_eval do
def build_selects_from_types(order)
select = ''
order.reverse.each do |type|
separator = separator(type) unless type == order.first # don't add on last field
select.insert(0, separator.to_s + send("select_#{type}").to_s)
end
select.insert(0, '<p>HI!!</p>') # or whatever...
select.html_safe
end
end
然后我在 environment.rb 的底部需要“覆盖”,但是在启动 WEBrick 时出现此错误:
~/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:479:in `load_missing_constant': ActionView::Helpers 不缺 常量日期时间选择器! (参数错误)
所以我显然不知道自己在做什么,但这似乎是一个合理的尝试,至少。
上面的错误似乎暗示它找不到 DateTimeSelector 类,但我查看了 ~/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/ 中的代码lib/action_view/helpers/date_helper.rb 我认为我的模块层次结构是正确的。是因为它是一个私有 Rails 类吗?
欢迎任何想法:)
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 datepicker overriding