1

尝试将项目从 Rails 3.2 更新到 Rails 4.0。在更新了一些 gem 之后,我遇到了一些错误和弃用,例如在运行“rails s”时使用哈希调用 #scope。修复后,“rails s”可以工作,但是当我尝试去 localhost 测试我的 webapp 时,我收到了这个错误:

    ActionView::Template::Error (wrong number of arguments (2 for 1)):
     5:       %th Activities
     6:       %th.w140
     7:   %tbody
     8:     - (list = latest_updates_list(@filter[:latest_updates_options])).each do |item|
     9:       %tr= latest_updates_item_helper(item)
    10:
    11:     - if list.length == 0
  app/helpers/dashboard_helper.rb:33:in `latest_updates_list'
  app/views/dashboard/_index.html.haml:8:in `_app_views_dashboard__index_html_haml__3401685304950220196_70213556660400'
  app/views/dashboard/index.html.haml:6:in `_app_views_dashboard_index_html_haml___725444960778701440_70213519668520'

这是 'latest_updates_list' 方法:

def latest_updates_list(option=nil)
    client_ids = current_user.actual_client_ids

    services = {}
    Service.where(:client_id => client_ids).each{|s| services[s.id] = {:name => s.name, :frequency_name => s.frequency_short_text, :per_hour => s.per_hour?} }

    reports = []
    invoices = []
    tickets = []
    employees = []

    list = []
    case option.to_sym
    when :reports
      reports = Report.for_latest_updates(client_ids) if (user_admin? || user_can_report?)
    when :invoices
      invoices = Invoice.for_latest_updates(client_ids) if (user_admin? || user_can_invoice?)
    when :tickets
      tickets = Ticket.for_latest_updates(client_ids) if (user_admin? || user_can_ticket?)
    when :employees
      employees = Employee.for_latest_updates(current_user.filter_client_id, client_ids) if user_admin?
    else
      reports = Report.for_latest_updates(client_ids) if (user_admin? || user_can_report?)
      invoices = Invoice.for_latest_updates(client_ids) if (user_admin? || user_can_invoice?)
      tickets = Ticket.for_latest_updates(client_ids) if (user_admin? || user_can_ticket?)
      employees = Employee.for_latest_updates(current_user.filter_client_id, client_ids) if user_admin?
    end

    list += reports.collect do |r|
       {
         :date => r.updated_at,
         :entity => 1,
         :status_text => latest_update_report_status_text(r),
         :reports_services_text => latest_updates_reports_services_text(r, r.reports_services),
         :report_id => r.id}
    end unless reports.empty?

    list += invoices.collect do |i|
       {
         :date => i.updated_at,
         :entity => 2,
         :status_text => latest_update_invoice_status_text(i),
         :invoice_reports_services_text => latest_updates_invoice_reports_services_text(services, i.reports),
         :invoice_id => i.id}
    end unless invoices.empty?

    list += tickets.collect do |t|
       {
         :date => latest_update_ticket_date(t),
         :entity => 3,
         :status_text => latest_update_ticket_status_text(t),
         :description => t.description_text,
         :ticket_id => t.id}
    end unless tickets.empty?

    list += employees.collect do |e|
       {
         :date => e.updated_at,
         :entity => 4,
         :description => e.text_for_stream,
         :employee_id => e.employee_id}
    end unless employees.empty?

    sorted_list = list.sort{|a, b| a[:date].to_i <=> b[:date].to_i}
    list = sorted_list.reverse!
    list = list.take(50)
  end

这是 'latest_updates_list' 中的第 33 行:

    Service.where(:client_id => client_ids).each{|s| services[s.id] = {:name => s.name, :frequency_name => s.frequency_short_text, :per_hour => s.per_hour?} }

这是我的 Gemfile.lock

GIT
  remote: git://github.com/rails/sass-rails.git
  revision: 8588b7b31d708a91516ae3bda0f57601a860ec28
  branch: 4-0-stable
  specs:
    sass-rails (4.0.5)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.2.2)
      sprockets (~> 2.8, < 3.0)
      sprockets-rails (~> 2.0)

GIT
  remote: git://github.com/syreclabs/ckeditor.git
  revision: f0d175a66876d9b3453fb47a7914789660a36a15
  specs:
    ckeditor (4.0.6)
      mime-types
      orm_adapter

GIT
  remote: https://github.com/bearded-nemesis/heroku-rglpk.git
  revision: 760859ce23c6e9d253324a584da6ee351700c48f
  specs:
    heroku-rglpk (0.2.1)

PATH
  remote: lib/plugins/xeroizer-payroll-merged
  specs:
    xeroizer (2.16.5)
      activesupport
      builder (>= 2.1.2)
      i18n
      nokogiri
      oauth (>= 0.4.5)
      tzinfo

GEM
  remote: http://rubygems.org/
  specs:
    actionmailer (4.0.0)
      actionpack (= 4.0.0)
      mail (~> 2.5.3)
    actionpack (4.0.0)
      activesupport (= 4.0.0)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.0)
      activesupport (= 4.0.0)
      builder (~> 3.1.0)
    activerecord (4.0.0)
      activemodel (= 4.0.0)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.0)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.4)
    activesupport (4.0.0)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    addressable (2.3.6)
    annotate (2.6.3)
      activerecord (>= 2.3.0)
      rake (>= 0.8.7)
    arel (4.0.2)
    authlogic (3.4.1)
      activerecord (>= 3.2)
      activesupport (>= 3.2)
      request_store (~> 1.0.5)
    autoparse (0.3.3)
      addressable (>= 2.3.1)
      extlib (>= 0.9.15)
      multi_json (>= 1.0.0)
    awesome_print (1.2.0)
    aws-eventstream (1.0.2)
    aws-partitions (1.149.0)
    aws-sdk (1.38.0)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
      uuidtools (~> 2.1)
    aws-sdk-core (3.48.3)
      aws-eventstream (~> 1.0, >= 1.0.2)
      aws-partitions (~> 1.0)
      aws-sigv4 (~> 1.1)
      jmespath (~> 1.0)
    aws-sdk-kms (1.16.0)
      aws-sdk-core (~> 3, >= 3.48.2)
      aws-sigv4 (~> 1.1)
    aws-sdk-s3 (1.36.0)
      aws-sdk-core (~> 3, >= 3.48.2)
      aws-sdk-kms (~> 1)
      aws-sigv4 (~> 1.0)
    aws-sigv4 (1.1.0)
      aws-eventstream (~> 1.0, >= 1.0.2)
    bcrypt (3.1.7)
    bcrypt-ruby (3.1.5)
      bcrypt (>= 3.1.3)
    builder (3.1.4)
    capybara (2.2.1)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    celluloid (0.15.2)
      timers (~> 1.1.0)
    celluloid-io (0.15.0)
      celluloid (>= 0.15.0)
      nio4r (>= 0.5.0)
    climate_control (0.0.3)
      activesupport (>= 3.0)
    cocaine (0.5.4)
      climate_control (>= 0.0.3, < 1.0)
    coderay (1.1.0)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.7.0)
    concurrent-ruby (1.1.5)
    daemons (1.1.9)
    dalli (2.7.0)
    database_cleaner (1.2.0)
    delayed_job (4.0.1)
      activesupport (>= 3.0, < 4.2)
    delayed_job_active_record (4.0.1)
      activerecord (>= 3.0, < 4.2)
      delayed_job (>= 3.0, < 4.1)
    diff-lcs (1.2.5)
    dotenv (0.7.0)
    erubis (2.7.0)
    eventmachine (1.0.3)
    exception_notification (4.0.1)
      actionmailer (>= 3.0.4)
      activesupport (>= 3.0.4)
    execjs (2.0.2)
    extlib (0.9.16)
    factory_girl (4.4.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.4.1)
      factory_girl (~> 4.4.0)
      railties (>= 3.0.0)
    faraday (0.9.0)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.0)
    ffi-compiler (0.1.3)
      ffi (>= 1.0.0)
      rake
    font_assets (0.1.11)
      rack
    foreigner (1.6.1)
      activerecord (>= 3.0.0)
    foreman (0.64.0)
      dotenv (~> 0.7.0)
      thor (>= 0.13.6)
    formatador (0.2.4)
    google-api-client (0.7.1)
      addressable (>= 2.3.2)
      autoparse (>= 0.3.3)
      extlib (>= 0.9.15)
      faraday (>= 0.9.0)
      jwt (>= 0.1.5)
      launchy (>= 2.1.1)
      multi_json (>= 1.0.0)
      retriable (>= 1.4)
      signet (>= 0.5.0)
      uuidtools (>= 2.1.0)
    grocer (0.5.0)
    guard (2.6.0)
      formatador (>= 0.2.4)
      listen (~> 2.7)
      lumberjack (~> 1.0)
      pry (>= 0.9.12)
      thor (>= 0.18.1)
    guard-rspec (4.2.8)
      guard (~> 2.1)
      rspec (>= 2.14, < 4.0)
    haml (4.0.5)
      tilt
    haml-rails (0.4)
      actionpack (>= 3.1, < 4.1)
      activesupport (>= 3.1, < 4.1)
      haml (>= 3.1, < 4.1)
      railties (>= 3.1, < 4.1)
    hike (1.2.3)
    i18n (0.9.5)
      concurrent-ruby (~> 1.0)
    jmespath (1.4.0)
    jquery-rails (3.1.0)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (4.2.1)
      railties (>= 3.2.16)
    json (1.8.6)
    jwt (0.1.11)
      multi_json (>= 1.5)
    launchy (2.4.2)
      addressable (~> 2.3)
    listen (2.7.1)
      celluloid (>= 0.15.2)
      celluloid-io (>= 0.15.0)
      rb-fsevent (>= 0.9.3)
      rb-inotify (>= 0.9)
    lumberjack (1.0.5)
    mail (2.5.5)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    memcachier (0.0.2)
    method_source (0.8.2)
    mime-types (1.25.1)
    mini_portile (0.5.3)
    minitest (4.7.5)
    multi_json (1.13.1)
    multipart-post (2.0.0)
    newrelic_rpm (3.7.3.204)
    nio4r (1.2.1)
    nokogiri (1.6.1)
      mini_portile (~> 0.5.0)
    oauth (0.5.3)
    orm_adapter (0.5.0)
    paperclip (3.5.4)
      activemodel (>= 3.0.0)
      activesupport (>= 3.0.0)
      cocaine (~> 0.5.3)
      mime-types
    pg (0.17.1)
    pg_array_parser (0.0.9)
    polyglot (0.3.5)
    postgres_ext (2.0.0)
      activerecord (~> 4.0.0)
      arel (~> 4.0.0)
      pg_array_parser (~> 0.0.9)
    protected_attributes (1.0.3)
      activemodel (>= 4.0.0, < 5.0)
    pry (0.9.12.6)
      coderay (~> 1.0)
      method_source (~> 0.8)
      slop (~> 3.4)
    quiet_assets (1.0.2)
      railties (>= 3.1, < 5.0)
    rack (1.5.5)
    rack-cors (0.2.9)
    rack-test (0.6.3)
      rack (>= 1.0)
    rails (4.0.0)
      actionmailer (= 4.0.0)
      actionpack (= 4.0.0)
      activerecord (= 4.0.0)
      activesupport (= 4.0.0)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.0)
      sprockets-rails (~> 2.0.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.2)
    rails_stdout_logging (0.0.3)
    railties (4.0.0)
      actionpack (= 4.0.0)
      activesupport (= 4.0.0)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (12.3.2)
    rb-fsevent (0.9.4)
    rb-inotify (0.9.3)
      ffi (>= 0.5.0)
    request_store (1.0.5)
    retriable (1.4.1)
    rspec (2.14.1)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rspec-core (2.14.8)
    rspec-expectations (2.14.5)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-mocks (2.14.6)
    rspec-rails (2.14.2)
      actionpack (>= 3.0)
      activemodel (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rubyzip (1.1.7)
    sass (3.2.19)
    scrypt (1.2.1)
      ffi-compiler (>= 0.0.2)
      rake
    shortener (0.3.0)
      rails (>= 3.0.7)
    signet (0.5.0)
      addressable (>= 2.2.3)
      faraday (>= 0.9.0.rc5)
      jwt (>= 0.1.5)
      multi_json (>= 1.0.0)
    slop (3.5.0)
    spork (0.9.2)
    sprockets (2.12.5)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    strip_attributes (1.5.1)
      activemodel (>= 3.0, < 5.0)
    thin (1.6.2)
      daemons (>= 1.0.9)
      eventmachine (>= 1.0.0)
      rack (>= 1.0.0)
    thor (0.20.3)
    thread_safe (0.3.6)
    tilt (1.4.1)
    timers (1.1.0)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    trim_blobs (0.0.1)
      activerecord (>= 3.2.0)
    twilio-ruby (3.11.5)
      builder (>= 2.1.2)
      jwt (>= 0.1.2)
      multi_json (>= 1.3.0)
    tzinfo (0.3.55)
    uglifier (2.5.0)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    uuidtools (2.1.4)
    xpath (2.0.0)
      nokogiri (~> 1.3)
    yui-compressor (0.12.0)

PLATFORMS
  ruby

DEPENDENCIES
  annotate
  authlogic
  awesome_print
  aws-sdk
  aws-sdk-s3
  bcrypt-ruby (~> 3.1.2)
  capybara
  ckeditor!
  coffee-rails
  dalli
  database_cleaner
  delayed_job_active_record
  exception_notification
  factory_girl_rails
  ffi (= 1.9.0)
  font_assets
  foreigner
  foreman
  google-api-client
  grocer
  guard-rspec
  haml
  haml-rails
  heroku-rglpk!
  jquery-rails
  jquery-ui-rails
  memcachier
  multipart-post
  newrelic_rpm
  paperclip (~> 3.0)
  pg
  postgres_ext
  protected_attributes
  quiet_assets
  rack-cors
  rails (= 4.0)
  rails_12factor
  rb-fsevent
  rspec
  rspec-core
  rspec-mocks
  rspec-rails
  rubyzip (~> 1.1.0)
  sass-rails!
  scrypt
  shortener
  spork
  strip_attributes
  thin
  trim_blobs
  twilio-ruby
  uglifier
  xeroizer!
  yui-compressor

RUBY VERSION
   ruby 2.1.10p492

BUNDLED WITH
   1.17.3

我相信这一定是一个 gem 问题,因为它以前工作过,而且我没有更改这些文件中的任何内容。

这是我更新的宝石的副本:

Using activesupport 4.0.0 (was 3.2.18)
Using builder 3.1.4 (was 3.0.4)

Using rack 1.5.5 (was 1.4.5)

Using actionpack 4.0.0 (was 3.2.18)

Using actionmailer 4.0.0 (was 3.2.18)
Using activemodel 4.0.0 (was 3.2.18)

Using activerecord-deprecated_finders 1.0.4

Using arel 4.0.2 (was 3.0.3)
Using activerecord 4.0.0 (was 3.2.18)

Using railties 4.0.0 (was 3.2.18)
Using coffee-rails 4.0.1 (was 3.2.2)

Using postgres_ext 2.0.0 (was 1.0.0)

Using sprockets 2.8.3 (was 2.2.2)
Using sprockets-rails 2.0.1
Using rails 4.0.0 (was 3.2.18)

Using sass 3.2.19 (was 3.3.5)
Using sass-rails 4.0.5 (was 3.2.6)

这是我使用 binding.pry 打印出“client_ids”时得到的结果:

=> [76,
 73,
 64,
 51,
 22,
 67,
 75,
 36,
 83,
 32,
 62,
 55,
 18,
 20,
 60,
 69,
 68,
 1,
 9,
 77,
 78,
 33,
 57,
 59,
 41,
 63,
 43,
 53,
 71,
 66,
 38,
 58,
 61,
 80,
 6,
 65,
 70,
 81,
 74,
 82,
 79,
 42,
 56,
 50,
 49,
 47,
 45,
 44,
 48]

如果我使用 pry 调用该行:

[7] pry(#<#<Class:0x007fecc2fdafc8>>)> Service.where(:client_id => client_ids).each{|s| services[s.id] = {:name => s.name, :frequency_name => s.frequency_short_text, :per_hour => s.per_hour?} }
ArgumentError: wrong number of arguments (2 for 1)
from /Users/justin/.rvm/gems/ruby-2.1.10/gems/postgres_ext-2.0.0/lib/postgres_ext/arel/visitors/to_sql.rb:6:in `visit_Array'
4

1 回答 1

1

你需要升级你的postgres_ext宝石。

您当前安装了 Arel 4.0.2 并安装了 PostgresExt 2.0.0。

我看到 PostgresExt 2.1.3 说“修复 Arel 4.0.1 问题”。 https://github.com/DavyJonesLocker/postgres_ext/blob/master/CHANGELOG.md#213

您的 PostgresExt 版本与您安装的 Rails 版本不兼容。因为你最近添加的堆栈跟踪,我才开始顿悟。

from /Users/justin/.rvm/gems/ruby-2.1.10/gems/postgres_ext-2.0.0/lib/postgres_ext/arel/visitors/to_sql.rb:6:in `visit_Array'

请注意,问题在于 PostgresExt gem 中的参数数量错误。

注意到这个提交有什么有趣的地方吗?

https://github.com/DavyJonesLocker/postgres_ext/commit/4ac6184d4bbfd763044b28f98344a02cf688cca3

它采用该visit_Array方法并使其使用两个参数而不是 1。这就是问题所在。ActiveRecord 正在尝试使用 2 个参数调用 Arel 方法,但 PostgresExt 已覆盖该方法以添加一些功能,并且它们的覆盖仅需要 1 个参数。这就是为什么这种覆盖核心功能的 gem 使用起来有点危险。您需要良好的测试覆盖率,因为当 Rails 更改其 gem 的内部位时,它会很快破坏这个 PostgresExt gem。

您还应该考虑从这个 gem 迁移出去,因为它说它不再被维护。

我的一位同事最近向我展示了这个名为 ActiveRecordExtended 的 gem(奇怪的名字,考虑到它只是 Postgres,但哦,好吧)。我从来没有使用过它,所以我不能保证它,但它似乎做了 PostgesExt 所做的事情,但也得到了维护。

https://github.com/georgekaraszi/ActiveRecordExtended

于 2019-04-12T04:07:56.613 回答