gpt4 book ai didi

ruby-on-rails - Rails 渲染状态 : :not found missing template error

转载 作者:行者123 更新时间:2023-12-04 03:48:30 26 4
gpt4 key购买 nike

在为类(class)开发应用程序时,我遇到了一个绊脚石:

The error screen

这是我的股票 Controller 错误,其中出现错误:

class StocksController < ApplicationController
def search
if params[:stock]
@stock = Stock.find_by_ticker(params[:stock])
@stock ||= Stock.new_from_lookup(params[:stock])
end

if @stock
render json: @stock
#render partial: 'lookup'

else
render status: :not_found ,nothing: true
end

end

end

在类(class)中,他们和我有相同的代码,但对他们来说,它有效。我知道的唯一区别是他们正在使用 Rails 4(Nitrous),而我正在使用 Rails 5(Mac OS X/Atom IDE/GitLab 存储库)。如果可以,请帮助我!在此先感谢您!

最佳答案

:nothing选项是 deprecated并将在 Rails 5.1 中删除。使用 head以空响应正文响应的方法。

尝试这个:

render body: nil, status: :not_found

或者:
head :not_found

请不要将错误发布为图像,复制文本

关于ruby-on-rails - Rails 渲染状态 : :not found missing template error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46263007/

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