Ruby on rails 错误-分配属性时,必须将哈希作为参数传递
我有一个资金表下面是它的管理资金显示页面。我想添加一个功能,以便管理员可以添加支票削减日期直接从这个页面与提交按钮在最后Ruby on rails 错误-分配属性时,必须将哈希作为参数传递,ruby-on-rails,ruby,ruby-on-rails-5,Ruby On Rails,Ruby,Ruby On Rails 5,我有一个资金表下面是它的管理资金显示页面。我想添加一个功能,以便管理员可以添加支票削减日期直接从这个页面与提交按钮在最后 <%= form_tag add_cheque_date_path, :method => 'patch' do %> <tbody> <% @fundings.each do |funding| %> <tr> <td><%= funding.child.parent.parent
<%= form_tag add_cheque_date_path, :method => 'patch' do %>
<tbody>
<% @fundings.each do |funding| %>
<tr>
<td><%= funding.child.parent.parent_1_firstname %></td>
<td><%= funding.child.parent.email %></td>
<td><%= funding.activity_start_date %></td>
<td><%= funding.date_submitted %></td>
<td><%= funding.status %></td>
<td><%= date_field_tag "funding.cheque_cut_date", funding.cheque_cut_date %></td>
<td><%= link_to "View", parent_child_funding_path(funding.child.parent, funding.child, funding) %></td>
</tr>
<% end %>
</tbody>
</table>
<%= submit_tag "Submit" %>
<% end %>
routes.rb
patch 'admin/application-status', to: 'parents#add_cheque_date', as: 'add_cheque_date'
当我点击下面的“提交”按钮时,我得到的是一个错误。请帮我修一下
When assigning attributes, you must pass a hash as an argument.
更新传入文件中的所有属性
散列并保存记录。如果该对象无效,则将保存
将返回FAILE和false
但是在funding.update\u attributes(:check\u cut\u date)
中,您只放置键:check\u cut\u date
,没有任何值。请尝试下一步:
funding.update_attributes(funding_params)
此外,还有不止一个问题<代码>日期字段\标记“资金。支票截止日期”创建名称为资金。支票截止日期的字段
,但参数要求(:资金)。允许(:支票截止日期)
不允许密钥资金。支票截止日期
。同时更改字段名称:
<td><%= date_field_tag "funding[cheque_cut_date]", funding.cheque_cut_date %></td>
#or the same fields helpers type as other from this form
<td><%= f.date_field :cheque_cut_date %></td>
#或帮助程序在此表单中键入与其他字段相同的字段
form.html.erb
<td><%= date_field_tag "cheque_cut_date[#{funding.id}]", funding.cheque_cut_date, min: Date.today %></td>
<td><%= date_field_tag "cheque_cut_date[#{funding.id}]", funding.cheque_cut_date, min: Date.today %></td>
def add_cheque_date
fundings = params[:cheque_cut_date]
fundings.select do |k, v|
if v.present?
funding = Funding.find(k)
funding.update_attributes({cheque_cut_date: v})
end
end
end