我对我的控制器有一个动作,不需要模板或视图
Puma的日志
No template found for CartController#post, rendering head :no_content
Completed 204 No Content in 2249ms (ActiveRecord: 2.7ms | Allocations: 27968)
如何告诉 Rails 不需要模板?
当你想要一个没有内容的动作返回时,使用 head 方法只返回一个 HTTP 状态代码。
在你的例子中(
CartController#post
)最合适的回应可能是
head :created
返回 HTTP
201 Create
状态代码,没有更多内容。
你可以试试:
render json: @foo