如何解决如何在ajax-datables-rails gem中使用postgres函数
我正在使用Rails 5上的ruby中的ajax-datables-rails gem在数据表中的视图中显示我的模型的所有数据,使用模型对我来说是完美的数据表,问题出在我需要时为了显示功能带来的数据,我找不到在过程中使用该功能的方法。这是使用对我有用的计费模型的代码
这是我的数据表文件:
class VentaDatatable < AjaxDatatablesRails::ActiveRecord
extend Forwardable
def_delegators :@view,:current_user
def initialize(params,opts = {})
@view = opts[:view_context]
super
end
def view_columns
@view_columns ||= {
bill_number: { source: 'Billing.bill_number',cond: :like,searchable: false,orderable: false },date_bill: { source: 'Billing.date_bill',orderable: false }
}
end
def data
records.map do |record|
{
bill_number: record.bill_number,date_bill: record.date_bill
}
end
end
def get_raw_records
Billing.joins(:company,:client).from_company(current_user).includes(:company,:client).where.not(stated_at: 3)
end
end
这是替换代码以使用该功能的过程:
class VentaDatatable < AjaxDatatablesRails::ActiveRecord
extend Forwardable
def_delegators :@view,opts = {})
@view = opts[:view_context]
super
end
def view_columns
@view_columns ||= {
bill_number: { source: "['field1']",date_bill: { source: "['field2']",orderable: false }
}
end
def data
@function.to_a.each do |record|
{
bill_number: record['field1'],date_bill: record['field2']
}
end
end
def get_raw_records
@function = ActiveRecord::Base.connection.execute("SELECT * FROM get_sales_invoice_report(56,'2020-10-01','2020-10-14',0)")
end
end
但是当我尝试使用该功能时,它将在控制台中显示此错误:
NoMethodError (undefined method `where' for #<PG::Result:0x00007f18f3fe7910>):
app/controllers/reports_controller.rb:58:in `block (2 levels) in venta_busqueda'
app/controllers/reports_controller.rb:56:in `venta_busqueda'
我该如何做才能将功能显示在数据表中?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。