Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.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 我可以传递多个参数以获得多个结果吗_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 4_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails 我可以传递多个参数以获得多个结果吗

Ruby on rails 我可以传递多个参数以获得多个结果吗,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,ruby-on-rails-3.2,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,Ruby On Rails 3.2,我正在创建一个API,其中有一个名为invoices的表,其中customerType是一个列。customerType只能有四个可能的值,即PCT、RVN、INT或OTH 现在,我想传递如下URL: http://localhost:3000/api/quatertodate?group-by=customerNumber&customertype=RVN,INT http://localhost:3000/api/quatertodate?group-by=customerNumbe

我正在创建一个API,其中有一个名为invoices的表,其中customerType是一个列。customerType只能有四个可能的值,即PCT、RVN、INT或OTH

现在,我想传递如下URL:

http://localhost:3000/api/quatertodate?group-by=customerNumber&customertype=RVN,INT
http://localhost:3000/api/quatertodate?group-by=customerNumber&customertype=RVN,INT,OTH
http://localhost:3000/api/quatertodate?group-by=customerNumber
http://localhost:3000/api/quatertodate?group-by=customerNumber&customertype=PCT
http://localhost:3000/api/quatertodate?group-by=customerNumber&customertype=INT,PCT
但是,问题是,每当我传递单个customertype或根本不传递customertype时,它都会工作,但每当我在customertype中传递多个参数时,当它应该通过执行内部或查询返回这些参数的组合结果时,它就会返回null

在控制器的索引方法中,我有:

def index
    @invoices=if params[:'group-by'].present?
        if params[:'group-by'].to_s == "customerNumber" 

            if params[:customertype].present?
                Invoice.where(customerType: params[:customertype])
            else
                Invoice.order('customerNumber')
            end
        end
    end 
    render json: {status: 'SUCCESS', messasge: 'LOADED QUATERLY INVOICES', data: @invoices}, status: :ok
end

注:我能找到的最接近的答案是。任何帮助或解释都将不胜感激

这是因为您试图查询customerType等于RVN,INT的发票

您可能需要对customertype参数执行拆分:

这将为您生成一个查询:

SELECT `invoices`.* FROM `invoices` WHERE `invoices`.`customerType` IN ('RVN', 'INT')
而不是:

SELECT `invoices`.* FROM `invoices` WHERE `invoices`.`customerType` = 'RVN,INT'

你的解决方案有效。但你的解释澄清了疑问D
SELECT `invoices`.* FROM `invoices` WHERE `invoices`.`customerType` = 'RVN,INT'