好的,我正在慢慢掌握这一点,但我需要更多帮助。
我在我的视图中使用 time_select,因此我正在处理多参数分配。查看。
<%= pt.time_select :time, :twelve_hour => true, :minute_step => 5 %>
但是我正在做一件淘气的事情,并将它与数据库中没有的属性一起使用:
attr_accessor time
因此,由于它无法查看数据库,因此无法将多参数分配的内容拼凑起来,因此出现以下错误:
1 error(s) on assignment of multiparameter attributes
因此,我正在使用我在这里找到的信息:
composed_of :time,
:class_name => 'DateTime',
:mapping => [%w(DateTime to_s)],
:constructor => Proc.new{ |item| item },
:converter => Proc.new{ |item| item }
其他有用的链接:rubyonrails.org | apidock.com
这消除了错误,但我认为现在的问题是我使用的插件无法正常运行。我正在使用http://code.google.com/p/rails-twelve-hour-time-plugin/
. 目标是,我试图让时间选择有 3 个下拉菜单hh
::mm
am/pm
。
所以问题是:我需要如何调整我composed_of method
的插件才能正确转换它?或者有没有更好的方法来解决这种疯狂?
我不确定我需要什么映射器/构造器/转换器。现在该对象保留小时和分钟,除了小时没有转换为 24 小时(我认为插件应该负责处理)。