我正在使用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'“}”行上。我的语法似乎与我在网上找到的每个例子一致。我错过了什么?
答案 0 :(得分:0)
respond_to
阻止应解决ArgumentError (too few arguments)
问题:
respond_to do |format|
format.js { render js: "window.location='/objects/index'" }
end