0
我正在關注DataTables的遠程數據上的Railscast。要使其工作,你創建一個datatable.rbRails datables.rb中的undefined方法
我試圖定義在3個地方用在datatable.rb
這一個選擇是代碼:
class Workorders3Datatable
delegate :params, :h, :link_to, :number_to_currency, to: :@view
def initialize(view)
@view = view
end
def mygroupsopenwos(user)
select("workorders.*").joins("left outer join empgroups ON empgroups.workgroup_id=workorders.workgroup_id").where("empgroups.employee_id = ?", user).where("wostatus_id NOT IN (?)", [231, 230, 9263, 9264, 232])
end
def as_json(options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: workorders.mygroupsopenwos(current_user).count,
iTotalDisplayRecords: workorders.mygroupsopenwos(current_user).total_entries,,
aaData: data
}
end
private
def data
workorders.mygroupsopenwos(current_user).map do |workorder|
[
...
但是,我得到以下錯誤:
NoMethodError - undefined method `mygroupsopenwos' for #<ActiveRecord::Relation:0x007f9b046ccb08>:
如何定義mygroupsopenwos
這樣我就可以使用它?我應該把它放在控制器中嗎?
謝謝 - 我還添加了將'select(「workorders。*」)'改爲'workorders.select(「workorders。*」)' – Reddirt