Rendering JSON in controller

后端 未结 3 1847
长情又很酷
长情又很酷 2020-12-07 09:43

I was reading a book and in a chapter about Controllers when it talks about rendering stuff, for JSON it has an example like this but doesn\'t go in to details so I couldn\'

3条回答
  •  太阳男子
    2020-12-07 10:05

    For the instance of

    render :json => @projects, :include => :tasks
    

    You are stating that you want to render @projects as JSON, and include the association tasks on the Project model in the exported data.

    For the instance of

    render :json => @projects, :callback => 'updateRecordDisplay'
    

    You are stating that you want to render @projects as JSON, and wrap that data in a javascript call that will render somewhat like:

    updateRecordDisplay({'projects' => []})
    

    This allows the data to be sent to the parent window and bypass cross-site forgery issues.

提交回复
热议问题