【问题标题】:Rails request return status 200 but no response dataRails 请求返回状态 200 但没有响应数据
【发布时间】:2018-08-14 22:16:49
【问题描述】:

我有一个如下的 rails 动作:

def create
  ......
  if @course.save
    render json: { success: true, course: @course.info}
  else
    render json: { success: false, error_msg: @course.errors.full_messages }
  end

请求返回状态200但没有响应数据。

nginx 日志和 rails 日志看起来正常:

# nginx log
100.116.224.40 [14/Aug/2018:18:59:12 +0800] POST "xxxxx" 200 200 27 
"47.88.138.112" xxx

# rails log
method=POST path=xxxxformat=*/* controller=xxxx action=create 
status=200 duration=45.94 view=0.23 params=

【问题讨论】:

  • @Gabbar 谢谢回复!我试过了还是不行!
  • 您是否在 if 语句下方尝试过 byebug? @course.info 的价值是什么?
  • @course.info 是一个哈希,如果我删除它,仍然不起作用。

标签: ruby-on-rails ruby http nginx


【解决方案1】:

由于课程大概是一个哈希,请尝试course["info"]

如果这仍然不起作用,您可能需要使用 JSON.parse(course["info"]) 将信息哈希转换为 JSON

【讨论】:

    猜你喜欢
    • 2023-02-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 2019-04-09
    • 1970-01-01
    相关资源
    最近更新 更多