Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法使用filterrific进行筛选和搜索_Ruby On Rails_Lambda_Filterrific - Fatal编程技术网

Ruby on rails 无法使用filterrific进行筛选和搜索

Ruby on rails 无法使用filterrific进行筛选和搜索,ruby-on-rails,lambda,filterrific,Ruby On Rails,Lambda,Filterrific,当with_角色为空时,我可以进行筛选和搜索,但当我想使用with_角色:主管或工人进行搜索时,我遇到了一个问题: NoMethodError (undefined method `with_role' for #Array:0xb2499b54): app/controllers/workers_controller.rb:38:in index' 如何修复或转换该数组 这是我的密码 控制器 class WorkersController < ApplicationController

当with_角色为空时,我可以进行筛选和搜索,但当我想使用with_角色:主管或工人进行搜索时,我遇到了一个问题:

NoMethodError (undefined method `with_role' for #Array:0xb2499b54):
app/controllers/workers_controller.rb:38:in index'
如何修复或转换该数组

这是我的密码 控制器

class WorkersController < ApplicationController
  include WorkerHelper
  def index
    (@filterrific = initialize_filterrific(
      User.where(role: %w(supervisor worker), company_id: current_user.company_id),
      params[:filterrific],
      select_options: {
        with_role: [%w(Supervisor supervisor), %w(Técnico worker)],
        search_query: ['Nro. DNI', 'Nombres', 'Apellidos']
      },
      persistence_id: false
    )) || return
    @workers = @filterrific.find.paginate(per_page: 10, page: params[:page])
  end
end

我还不熟悉使用Filterrific Gem

您可能需要检查控制器中的select_选项行

with_role: [%w(Supervisor supervisor), %w(Técnico worker)],
检查[%wSupervisor supervisor,%wTécnico worker]正在调用的内容,我无法从您的模型中获取该内容。假设它是模型中定义的范围的选项

注意:在“选择选项”中

您正在此处以filterrific表单存储输入的任何选项。 _的选项_。。。方法返回可以作为选项传递给f.select的数组,因此这些方法在模型中定义

要了解更多信息,我建议您通过

我认为你可以做的另一件事是:

在模型中定义一个方法,以便在选项[%wSupervisor supervisor,%wTécnico worker]中进行分析

然后在控制器中调用方法选项,\u for,\u和\u角色选择\u选项,如下所示:

class WorkersController < ApplicationController
  include WorkerHelper
  def index
    (@filterrific = initialize_filterrific(
      User.where(role: %w(supervisor worker), company_id: current_user.company_id),
      params[:filterrific],
      select_options: {
        with_role: #Your ActiveRecord based model class.options_for_with_role e.g. Worker.options_for_with_role,
        search_query: ['Nro. DNI', 'Nombres', 'Apellidos']
      },
      persistence_id: false
    )) || return
    @workers = @filterrific.find.paginate(per_page: 10, page: params[:page])
  end
end

如果它不起作用,当找到一种方法来更改行用户时。whererole:%wsupervisor worker,company\u id:current\u User.company\u id也更改为基于ActiveRecord的模型类。

我也是使用FilterRigic Gem的新手

您可能需要检查控制器中的select_选项行

with_role: [%w(Supervisor supervisor), %w(Técnico worker)],
检查[%wSupervisor supervisor,%wTécnico worker]正在调用的内容,我无法从您的模型中获取该内容。假设它是模型中定义的范围的选项

注意:在“选择选项”中

您正在此处以filterrific表单存储输入的任何选项。 _的选项_。。。方法返回可以作为选项传递给f.select的数组,因此这些方法在模型中定义

要了解更多信息,我建议您通过

我认为你可以做的另一件事是:

在模型中定义一个方法,以便在选项[%wSupervisor supervisor,%wTécnico worker]中进行分析

然后在控制器中调用方法选项,\u for,\u和\u角色选择\u选项,如下所示:

class WorkersController < ApplicationController
  include WorkerHelper
  def index
    (@filterrific = initialize_filterrific(
      User.where(role: %w(supervisor worker), company_id: current_user.company_id),
      params[:filterrific],
      select_options: {
        with_role: #Your ActiveRecord based model class.options_for_with_role e.g. Worker.options_for_with_role,
        search_query: ['Nro. DNI', 'Nombres', 'Apellidos']
      },
      persistence_id: false
    )) || return
    @workers = @filterrific.find.paginate(per_page: 10, page: params[:page])
  end
end
如果不起作用,请在找到将行用户更改的方法时。whererole:%wsupervisor worker,company_id:current_User.company_id也更改为基于ActiveRecord的模型类

class WorkersController < ApplicationController
  include WorkerHelper
  def index
    (@filterrific = initialize_filterrific(
      User.where(role: %w(supervisor worker), company_id: current_user.company_id),
      params[:filterrific],
      select_options: {
        with_role: #Your ActiveRecord based model class.options_for_with_role e.g. Worker.options_for_with_role,
        search_query: ['Nro. DNI', 'Nombres', 'Apellidos']
      },
      persistence_id: false
    )) || return
    @workers = @filterrific.find.paginate(per_page: 10, page: params[:page])
  end
end