在我的api/posts_controller.rb
中,我有以下代码:
def create
if invalid?
render status: 422, json: {message: 'this post is invalid'}
return
end
@post = Post.create!(post_params)
render 'api/posts/show'
end
如果帖子无效,它会在开发过程中呈现json错误消息,但在测试和生产中,主体将被删除,只剩下状态代码。