Rails在测试和生产中过滤掉json正文和4xx状态代码

时间:2016-12-13 10:55:16

标签: ruby-on-rails json ruby

在我的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错误消息,但在测试和生产中,主体将被删除,只剩下状态代码。

0 个答案:

没有答案