无法刷新错误数组

Cannot flash errors array

我在刷新错误数组时遇到问题。目前我正在调用 notice: errors,但它返回的数组看起来像这样

["Please enter score range one.", "Please enter score range two.", "Please enter range between 1 and 100 for score one.", "Please enter range between 1 and 100 for score two."]

如果我调用 flash: errors,我会得到这个错误

undefined method 'keys' for #<Array:0x0000010f196198>

执行此操作的更好方法是什么?我的代码如下

if beg_score.present? && end_score.present? && beg_score.to_i.between?(1, 100) && end_score.to_i.between?(1, 100)
  CallLogByScoreWorker.perform_async(beg_score, end_score, query)
  redirect_to call_logs_path, notice: 'Calls were successfully made.'
else
  errors = []
  unless beg_score.present?
    errors << 'Please enter score range one.'
  end
  unless end_score.present?
    errors << 'Please enter score range two.'
  end
  unless beg_score.to_i.between?(1, 100)
    errors << 'Please enter range between 1 and 100 for score one.'
  end
  unless end_score.to_i.between?(1, 100)
    errors << 'Please enter range between 1 and 100 for score two.'
  end
redirect_to call_logs_path, flash: errors

而不是:

redirect_to call_logs_path, flash: errors

做:

redirect_to call_logs_path, notice: errors.join(' ')

这样,它会return一个像下面这样的字符串:

'Please enter score range one. Please enter score range two. Please enter range between 1 and 100 for score one. Please enter range between 1 and 100 for score two.'

查看有关 join 方法的 RubyDocs 文档。