简体   繁体   English

使用update_all更新日期属性

[英]Using update_all to update a date attribute

I have a payments table and I want to be able to update all the date_of_payment fields simultaneously, ie with the same date. 我有一个付款表,我希望能够同时(即使用同一日期)更新所有date_of_payment字段。

In my view I have the following 我认为我有以下几点

<%= form_tag update_date_payments_path, :class => 'form_for_all', method: :put do %>
    <%= date_select(:date_of_payment, :order => [:year, :month, :day] ) %>
<div class="actions">
  <%= submit_tag 'Save' %>
</div>
<% end %>

And in my controller I have: 在我的控制器中,我有:

  def update_date
    Payment.update_all(params[:date_of_payment])
  end

The error I'm getting is: 我得到的错误是:

SQLite3::SQLException: no such column: {:order=>: UPDATE "payments" SET "{:order=>" = '--- - '':year, :month, :day'' - !ruby/hash:ActiveSupport::HashWithIndifferentAccess ! SQLite3 :: SQLException:没有这样的列:{:order =>:UPDATE“ payments” SET“ {:order =>” ='----'':year,:month,:day''-!ruby / hash :ActiveSupport :: HashWithIndifferentAccess! ''}(1i)'': ''2014'' ! ''}(1i)'':``2014''! ''}(2i)'': ''3'' ! ''}(2i)'':``3''! ''}(3i)'': ''24'' ' ''}(3i)'':``24'''

I must confess that I'm a bit confused about what exactly this error is about. 我必须承认,我对该错误的确切含义有些困惑。 Is the code in my controller incorrect? 控制器中的代码不正确吗? Or is there something wrong with the form? 还是表格有问题? As I said, I don't fully understand forms yet so any help at all would be greatly appreciated. 正如我说的,我还不完全了解表单,因此对您的任何帮助将不胜感激。

Check the syntax of update_all . 检查update_all的语法。 I think you need something like: 我认为您需要以下内容:

Payment.update_all(date_of_payment: params[:date_of_payment])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM