gpt4 book ai didi

ruby-on-rails - 弃用警告 : before_filter is deprecated and will be removed in Rails 5. 1. 改用 before_action

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:26 25 4
gpt4 key购买 nike

这里发生了什么?我正在尝试通过使用 JSON 数据类型的 ajax 调用添加数据。但每次我尝试添加数据时,它都会显示错误,如图所示。

Rails log in terminal

我认为它总是响应html格式但不响应json格式。

def new
@batch = Batch.new
respond_to do |format|
format.json
format.html
end
end

def create
@batch = Batch.new(batch_param)
puts "/n/n/n/n name: #{@batch.name} /n/n/n/n"
respond_to do |format|
if @batch.save
format.json { render json: @batch, status: :created, location: @batch }
format.html { redirect_to @batch, notice: "Save process completed!" }
else
format.html {
flash.now[:notice]="Save proccess coudn't be completed!"
render :new
}
format.json { render json: @batch.errors, status: :unprocessable_entity}
end
end
end

最佳答案

这只是折旧警告,如果您将应用程序升级到 Rails 5.1,它可能会变成错误,正如日志中明确提到的那样,您可以通过搜索您正在使用 的 Controller 来解决它>before_filter 并将其替换为 before_action

before_action 与早期版本的 Rails 中的 before_filter 做同样的事情(在请求命中 Controller 中的操作之前运行一些代码)。

关于ruby-on-rails - 弃用警告 : before_filter is deprecated and will be removed in Rails 5. 1. 改用 before_action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41572287/

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