Ruby Rails 7.1.3 中的参数顺序错误(给定 1,预期 0)

问题描述 投票:0回答:1

我正在尝试创建一个范围,该范围将按 Service 类中的categories.name 排序。 类别是包含服务类别名称的模型,我想按类别名称字段排序,但出现以下错误: 参数数量错误(给定 1,预期 0)

error ruby

有错吗?

我已经改变了rails 7.1.3中调用mysql命令的所有方式,并且得到了同样的错误。

范围代码是:

  scope :left_join_category, -> { joins("LEFT JOIN categories ON categories.id = services.category_id").select("services.*, CONCAT(IFNULL(CONCAT(services.internal_reference_code, ' - '), ''), services.name) AS fullname, IFNULL(categories.id,  -1) AS category_id, IFNULL(categories.name, '--') AS category_name" ) }

  scope :ordered_by_subfamily, -> { order("families.name ASC, subfamilies.name ASC, CONCAT(IFNULL(CONCAT(services.internal_reference_code, ' - '), ''), services.name) ASC") }

  scope :ordered_by_category, -> { order("categories.name ASC") }

  scope :ordered_by_service, -> { order("CONCAT(IFNULL(CONCAT(services.internal_reference_code, ' - '), ''), services.name) ASC") }



  

并且在控制器内部使用:

  def set_services_by_company
      @services_categories = Hash.new


  services = Service.with_company(@user.company_default).with_branch(nil).left_join_category.left_join_branch(@branch).ordered_by_category
ruby-on-rails ruby
1个回答
0
投票

在长作用域链中

services = Service.with_company(@user.company_default)
                  .with_branch(nil)
                  .left_join_category
                  .left_join_branch(@branch)
                  .ordered_by_category

您使用参数调用

left_join_branch(@branch)
,但
left_join_branch
作用域不接受参数。

将范围更改为

services = Service.with_company(@user.company_default)
                  .with_branch(nil)
                  .left_join_category
                  .left_join_branch
                  .ordered_by_category

可能已经解决了您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.