gpt4 book ai didi

ruby-on-rails - 无法刷新错误数组

转载 作者:行者123 更新时间:2023-12-03 08:29:57 26 4
gpt4 key购买 nike

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

[“请输入分数范围一。”,“请输入分数范围二。”,“请为分数之一输入1至100之间的范围。”,“请为分数二输入1至100之间的范围。”]

如果我调用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(' ')

这样,它将返回类似以下的字符串:
'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文档。

关于ruby-on-rails - 无法刷新错误数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28591758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com