繁体   English   中英

Rails:命令在format.json {…}内部不起作用

[英]Rails: Commands don't work inside format.json { … }

所以,我是新来的铁轨使用AJAX和进出口尝试format.htmlformat.json首次。

使用ajax提交数据一切正常,但是对于format.json,它不运行我希望它在成功提交时运行的命令。

 if @key.save
  format.html { 
     # Key update runs fine in format.html
    Key.find(@key.id).update(submitted_by: current_user.id)
  } 
 format.json {
      # Key update doesn't run in format.json
    Key.find(@key.id).update(submitted_by: current_user.id)
  }
else
 ....

为什么Key update命令不能在format.json中运行?

def create
  ......
  if @key.save
    Key.find(@key.id).update(submitted_by: current_user.id)
    respond_to |format|
      format.html
      format.js
      format.json
    end
  else
  ..........

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM