1

我想使用表单上的两个元素更新日期时间属性:text_field 和 time_select。这将使用户能够使用 datepicker (jquery ui) 选择日期,并使用下拉菜单选择时间:

在此处输入图像描述

但是,当我尝试更新我的表单时,我收到以下错误:

ActiveRecord::MultiparameterAssignmentErrors in StepsController#update

1 error(s) on assignment of multiparameter attributes

Parameters:

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"FxFbv9OFzCiYjNknZKUtwyAXR99uuOvy8uplv1cKaZE=",
 "step"=>{"description"=>"<p>Project description</p>\r\n",
 "published_on"=>"05/30/2013",
 "published_on(4i)"=>"15",
 "published_on(5i)"=>"19"},
 "commit"=>"Update Step",
 "project_id"=>"92",
 "id"=>"0"}

如何将 text_field 和 time_select 中的参数组合成一个日期时间?

这是我的表格:

<%= f.text_field :published_on, :value=> (@step.published_on.strftime("%m/%d/%Y")) %>  at <%= f.time_select :published_on, :class=>"btn dropdown-toggle", :ampm=> true, :ignore_date=>true %>
4

1 回答 1

0

这是一个 ViewModel 可能有用的场景,但进入它会有点矫枉过正。

所以我想到的最好的选择是在客户端合并值,或者在从params变量构建对象之前在服务器端合并值。

在服务器端,它可以使用动作控制器过滤器来实现:
before_filter :merge_somefileds!, only: [:edit]

更多信息:http: //guides.rubyonrails.org/action_controller_overview.html#filters

于 2013-05-31T19:54:22.567 回答