首页 > 解决方案 > 更新到 Rails 4.0,突然传递了两个参数

问题描述

将 Rails gem 从 3.2 更新到 4.0 后,我收到此错误:

Completed 500 Internal Server Error in 332ms

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:35:in `latest_updates_list'
  app/views/dashboard/_index.html.haml:8:in `_app_views_dashboard__index_html_haml__3752706349525323962_70305528188080'
  app/views/dashboard/index.html.haml:6:in `_app_views_dashboard_index_html_haml__2066908720777569268_70305520107720'

这些是已更新的宝石:

Updated gems

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 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)

这是 'latest_updates_list' 方法:

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

    services = {}
    # binding.pry
    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?} }
    #Service.where(true).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

当我注释掉前 3 个 'list += ....do...' 时,应用程序将加载,除了没有获得他们获得的信息。我没有更改任何代码,所以它一定是由于 gem 更新。

标签: ruby-on-rails

解决方案


问题解决了,这是 postgres_ext gem 过时的问题。


推荐阅读