Ruby on Rails分页错误报告

时间:2019-05-15 07:47:46

标签: ruby-on-rails ruby ruby-on-rails-4

我最近开始学习ruby-on-rails,现在我可以创建一些东西,但是对语法仍然不太满意。 在报表视图中,当我转到第二页时,它给我一个错误。

但是分页在昨天得到了纠正。今天我使用params.dig方法编辑了一些复选框以保存复选框值。这些值也需要在第二页中显示。我的控制器出了什么问题

这是我的观点

 %br
          .row
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]","CUS", params.dig('search_customer_supplier', 'accounts_dealer_types.dealer_code') == "CUS"
              = label_tag "Organizational Customer"
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "SUP", params.dig('search_customer_supplier', 'accounts_dealer_types.dealer_code') == "SUP"
              = label_tag "Organzational Supplier"
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "INDCUS", params.dig('search_customer_supplier', 'accounts_dealer_types.dealer_code') == "INDCUS"
              = label_tag "Individual Customer"
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "INDSUP", params.dig('search_customer_supplier', 'accounts_dealer_types.dealer_code') == "INDSUP"
              = label_tag "Individual Supplier"

这是我的控制人

 def customer_supplier_report
    Organization
    Address
    ContactNumber
    refined_query = ""
    if params[:search].present? or params[:excel_report].present?

      search_customer_supplier = params[:search_customer_supplier]

      if params[:organization_children].present? and search_customer_supplier["id"].present?
        organization_id = search_customer_supplier["id"]
        organization = Organization.find(organization_id)
        anchestor_ids = organization.anchestors.map{|o| o[:member].id }
        search_customer_supplier["id"] = "(#{anchestor_ids.join(' OR ')})" if anchestor_ids.any?
      end

      params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] = params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].join(" OR ") if params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].present?

      # puts params[:search_customer_supplier]['accounts_dealer_types.dealer_code']

      customer_report = params[:search_customer_supplier].map { |k, v| "#{k}:#{v}" if v.present? }.compact
    else
      customer_report = ["accounts_dealer_types.dealer_code:(CUS OR SUP OR INDCUS OR INDSUP)"]
    end

在我的浏览器中,向我显示控制器中的错误行在哪里。

params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] = params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].join(" OR ") if params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].present?

这是我得到的输出错误

ReportsController#customer_supplier_report中的NoMethodError

“ CUS”的未定义方法“ join”:字符串您是什么意思? JSON

2 个答案:

答案 0 :(得分:0)

您收到此错误,因为join()Array class的方法。但是您的参数值是字符串类型。

即。

[1,2,3].join(' OR ') #=> "1 OR 2 OR 3"

但是

"aasd".join('OR') #=> will throw exception which you are getting.

检查您的参数值是否为正确的数组

答案 1 :(得分:0)

然后出现此错误输出

https://i.stack.imgur.com/AGB23.png

该项目也使用elasticsearch进行分页。我将在下面附加我的代码。

https://i.stack.imgur.com/TMSrw.png