0

我正在关注关于 DataTables 的远程数据的 Railscast。为了让它工作,你创建一个 datatable.rb

我正在尝试定义在 datatable.rb 中的 3 个位置使用的选择

这是代码:

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以便我可以使用它?我应该把它放在控制器中吗?

4

1 回答 1

0

删除workorders.之前workorders.mygroupsopenwos(current_user)

mygroupsopenwos是声明了几行的实例方法!

于 2013-06-19T14:40:29.173 回答