调用 format.js 时出现参数太少错误

Getting too few arguments error when calling format.js

我正在使用Rails 5.我有这个控制器方法

  def import_matching_objects
    matching_objects = objectTime.find_by_name_and_hometown_and_age(current_user)
    matching_objects.each do |object_time|
      user_object_time_match = UserObjectTimeMatch.new(:user_id => user.id,
                                                 :object_time_id => object_time.id,
                                                 :matches => true)
      # Save objects
      if !user_object_time_match.save_and_create_object_time
        puts "Failed to save user object: #{user_object_time_match.errors.full_messages}" 
      end 
    end 
    format.js { render js: "window.location='/objects/index'" } 
  end

但它产生了这个错误

ArgumentError (too few arguments):

app/controllers/user_object_time_matches_controller.rb:31:in `format'

在线"format.js { render js: "window.location='/objects/index'"}"。我的语法似乎与我在网上找到的每个示例都一致。我错过了什么?

一个 respond_to 块应该解决 ArgumentError (too few arguments) 问题:

respond_to do |format|
    format.js { render js: "window.location='/objects/index'" }   
end