简体   繁体   English

Ruby on Rails范围-ArgumentError:参数数量错误(1表示0)

[英]ruby on rails scopes - ArgumentError: wrong number of arguments(1 for 0)

I'm getting a wrong arguments error when invoking a scope: 调用范围时出现错误的参数错误:

Report.start_driver_time(Unit.find(3007),Driver.find(2),3,2013)

  scope :start_driver_time, lambda { |unit, driver, month, year|
    where("unit_id = ? AND
          driver_id = ? AND
          extract(MONTH FROM time) = ? AND
          extract(YEAR FROM time) = ?",
          unit.id, driver.id, month, year)
    .order("time asc")
    .min(:time)
  }
 #select(:time) select([:id, :time])

  scope :next_driver_time, lambda {|unit, time|
    joins(:alerts => {:alert_code => :alert_unit_codes})
    .where("reports.unit_id = ? AND
            reports.time >= ? AND
            alert_unit_codes.name = ?",
            unit.id, time, "Seat Belt OFF")
    .min(:time)        
  }

  scope :reports_within_driving_period, lambda { |start_time, end_time|
    where("unit_id = ? AND
            reports.time >= ? AND
            reports.time <= ?",
            start_time, end_time)
  }

stacktrace: 堆栈跟踪:

ArgumentError: wrong number of arguments(1 for 0)
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/relation/delegation.rb:37:in `min'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/relation/delegation.rb:37:in `method_missing'
    from /Users/johnmerlino/Documents/github/XKTrackingSystem/app/models/report.rb:40:in `block in <class:Report>'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/scoping/named.rb:180:in `call'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/scoping/named.rb:180:in `block (2 levels) in scope'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/scoping/default.rb:41:in `block in unscoped'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/relation.rb:241:in `block in scoping'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/scoping.rb:98:in `with_scope'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/relation.rb:241:in `scoping'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/scoping/default.rb:41:in `unscoped'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.5/lib/active_record/scoping/named.rb:180:in `block in scope'
    from (irb):1
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.5/lib/rails/commands/console.rb:47:in `start'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.5/lib/rails/commands/console.rb:8:in `start'
    from /Users/johnmerlino/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.5/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'1.9.3p0 :002 > exit

I think you intend to use minimum instead of min ? 我认为您打算使用最小值而不是min I haven't found a reference to min , so it might be using a different method that uses no parameters. 我尚未找到对min的引用,因此它可能使用了不使用任何参数的其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails 5 ArgumentError(参数数量错误(1代表0) - Rails 5 ArgumentError (wrong number of arguments (1 for 0) Rails 3 ArgumentError:错误的参数数目(3为1) - Rails 3 ArgumentError: wrong number of arguments (3 for 1) ArgumentError:错误的参数数量(0表示1)rails 4 - ArgumentError: wrong number of arguments (0 for 1) rails 4 升级到Rails 4和Ruby 2之后的ArgumentError(参数数量错误(1表示0)) - ArgumentError (wrong number of arguments (1 for 0)) after upgrade to Rails 4 and Ruby 2 Ruby在轨道上。 ArgumentError(参数数量错误(1代表5))。 标头应匹配 - Ruby on rails. ArgumentError (wrong number of arguments (1 for 5)). Header should match Ruby类ArgumentError:参数数量错误(1代表0) - Ruby class ArgumentError: wrong number of arguments (1 for 0) Rails 中的 ArgumentError(arguments 的编号错误(给定 5,预期为 1)) - ArgumentError (wrong number of arguments (given 5, expected 1)) in Rails Rails-ArgumentError(参数数量错误(给定1,预期为0)): - Rails - ArgumentError (wrong number of arguments (given 1, expected 0)): ArgumentError:rails中的更新方法的参数数目错误(1为2) - ArgumentError: wrong number of arguments (1 for 2) for update method in rails Rails-ArgumentError给定的参数个数错误3,预期为2 - Rails - ArgumentError wrong number of arguments given 3, expected 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM