{"action":"created","issue":{"url":"https://api.github.com/repos/mindpin/try-cv-split/issues/2","labels_url":"https://api.github.com/repos/mindpin/try-cv-split/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/mindpin/try-cv-split/issues/2/comments","events_url":"https://api.github.com/repos/mindpin/try-cv-split/issues/2/events","html_url":"https://github.com/mindpin/try-cv-split/issues/2","id":127851859,"number":2,"title":"返回JSON经常会遇到的状况","user":{"login":"destinyd","id":68806,"avatar_url":"https://avatars.githubusercontent.com/u/68806?v=3","gravatar_id":"","url":"https://api.github.com/users/destinyd","html_url":"https://github.com/destinyd","followers_url":"https://api.github.com/users/destinyd/followers","following_url":"https://api.github.com/users/destinyd/following{/other_user}","gists_url":"https://api.github.com/users/destinyd/gists{/gist_id}","starred_url":"https://api.github.com/users/destinyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/destinyd/subscriptions","organizations_url":"https://api.github.com/users/destinyd/orgs","repos_url":"https://api.github.com/users/destinyd/repos","events_url":"https://api.github.com/users/destinyd/events{/privacy}","received_events_url":"https://api.github.com/users/destinyd/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-01-21T05:56:15Z","updated_at":"2016-01-21T07:48:34Z","closed_at":null,"body":"### 以下列举一些经常会遇到的状况，我们来思考如何应对以及处理\r\n\r\n#### 描述(desc)\r\n1. 大多数描述，可能是一段 **很长的字符串** ，但是在列表里面，我可能需要 **截取一小段** 来给用户一个简单的说明。\r\n2. 有些情况下，描述可能还使用了富文本编辑器，里面直接带有 **html** 标记，在列表描述中，我们要进行 **标记清除** 再进行 **截断**。\r\n3. 也有这种可能，描述使用的是 **markdown** 标记语言。\r\n\r\n#### 图片\r\n现在项目基本都在使用 **file-part-upload** ，单张图片基本需要添加字段 **file_entity_id** 或着 **image_url**。 \r\n**file_entity_id** 方式，可以根据所需要的情况，改变图片的预设大小比例。\r\n**image_url* 则基本为写死。\r\n但是返回时，大多数情况只需要一个当前情景下，转化好了的url。\r\n\r\n一般关系为1对1，也可能为1对多\r\n\r\n#### 文件、音频、视频等\r\n现在项目基本都在使用 **file-part-upload** ，基本需要添加字段 **file_entity_id** \r\n一般关系为1对多"},"comment":{"url":"https://api.github.com/repos/mindpin/try-cv-split/issues/comments/173486081","html_url":"https://github.com/mindpin/try-cv-split/issues/2#issuecomment-173486081","issue_url":"https://api.github.com/repos/mindpin/try-cv-split/issues/2","id":173486081,"user":{"login":"destinyd","id":68806,"avatar_url":"https://avatars.githubusercontent.com/u/68806?v=3","gravatar_id":"","url":"https://api.github.com/users/destinyd","html_url":"https://github.com/destinyd","followers_url":"https://api.github.com/users/destinyd/followers","following_url":"https://api.github.com/users/destinyd/following{/other_user}","gists_url":"https://api.github.com/users/destinyd/gists{/gist_id}","starred_url":"https://api.github.com/users/destinyd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/destinyd/subscriptions","organizations_url":"https://api.github.com/users/destinyd/orgs","repos_url":"https://api.github.com/users/destinyd/repos","events_url":"https://api.github.com/users/destinyd/events{/privacy}","received_events_url":"https://api.github.com/users/destinyd/received_events","type":"User","site_admin":false},"created_at":"2016-01-21T07:48:34Z","updated_at":"2016-01-21T07:48:34Z","body":"如果我们需要JSON带一些关联的数据，就直接在as_json里面添加，即可\r\n\r\n```\r\n  def index\r\n    @comments = Comment.all\r\n    render json: @comments.as_json(only: brief_fields, include: :post)\r\n  end\r\n\r\n  # GET /comments/1\r\n  # GET /comments/1.json\r\n  def show\r\n    render json: @comment.as_json(only: detail_fields)\r\n  end\r\n\r\n  private\r\n    def brief_fields\r\n      # 默认为 [:id, :title, :content]\r\n      [:id, :title]\r\n    end\r\n\r\n    def detail_fields\r\n      [:id, :title, :content]\r\n    end\r\n  def\r\n```\r\n"}}