标签管理功能的实现与优化
1. 修复 CommentsController 测试问题
在测试 CommentsController 时,出现了错误:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.split
# ./app/models/ticket.rb:16:in `tag!'
# ./app/controllers/comments_controller.rb:12:in `create'
错误源于 Ticket 模型的 tag! 方法中的 tags.split 调用。 tags 来自 CommentsController 的 create 动作传递的参数 params[:tags] ,当 params[:tags] 为 nil 时,调用 split 方法就会出错。
错误代码位置:
tags = tags.split(" ").map do |tag
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



