这是在我的控制器中
def results
#searches with tags
@pictures = Picture.all
@alltags = Tag.all
searchkey = params['my_input']
pList = []
listsize = 0
while listsize < @pictures.size
pList[listsize] = 0
listsize += 1
end
@alltags.each do |tag|
if searchkey == tag.tagcontent
pList[tag.picture.id-1] += 1
end
end
@pictures.each do |picture|
if searchkey == picture.name
pList[picture.id-1] += 1
end
end
@pictures = @pictures.sort {|pic1, pic2| pList[pic2.id-1] <=> pList[pic1.id - 1]}
结尾
调用此错误时出现此错误
SearchController 中的 NoMethodError#results
当你没想到时,你有一个 nil 对象!您可能期望有一个 Array 的实例。评估 nil.+ Rails.root 时发生错误:/Users/kevinmohamed/SnapSort/server
应用程序跟踪 | 框架跟踪 | 完整跟踪 app/controllers/search_controller.rb:31:in block in results'
app/controllers/search_controller.rb:29:in
each' app/controllers/search_controller.rb:29:in `results'
31 是 pList[picture.id-1] += 1 ,29 是 @pictures.each 做 |picture|,为什么会发生这个错误