【发布时间】:2021-10-20 12:03:45
【问题描述】:
我在运行 rails test 时收到了弃用警告。该警告如下。在确定我做错了什么方面提供任何帮助表示赞赏。
(编辑:旁注,渲染必须中断并从当前的控制器调用返回。我尝试使用ApplicationController.render(...) 代替当前的render 调用,但这并没有从控制器调用返回,我是收到:no_content rendered 的错误/警告。)
警告:
DEPRECATION WARNING: Rendering actions with '.' in the name is deprecated: actions/action_success.json (called from update at /<path>/app/controllers/table_base_controller.rb:39)
引发警告的代码就是在控制器中对render 的调用:
render('/actions/action_success.json', locals: {
view: action.lookup_view('default'),
action: action,
area: current_area,
account: current_account
})
我已尝试按照指示取消.json(也尝试添加template: <path>,尝试file: <path>),但是,我在测试控制台中收到此错误:
Error:
TableControllerTest#test_Admin_should_update_via_loan_table:
ActionView::MissingTemplate: Missing template actions/action_success with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
* "/<path>/app/views"
app/controllers/table_base_controller.rb:39:in `update'
app/controllers/application_controller.rb:79:in `with_account'
test/controllers/table_controller_test.rb:14:in `block in <class:TableControllerTest>'
有问题的文件(路径:app/views/actions/action_success.json.jbuilder):
# frozen_string_literal: true
json.status 'success'
json.status_code 200
json.messages action.messages
if view
json.result do
json.partial! view.to_s, result: action.result, locals: { area: area }
end
else
json.result action.result
end
【问题讨论】:
-
您的请求点击该操作不是请求 json 响应,因此它正在尝试呈现 HTML
标签: ruby-on-rails ruby-on-rails-6.1