国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Ruby on Rails中的ActiveResource使用詳解

2019-10-26 19:28:19
字體:
來源:轉載
供稿:網友

當 HTTP 響應是一個與存在的格式不同的格式時(XML 和 JSON),需要某些額外的格式解析,創一個你慣用的格式,并在類別中使用它。慣用的格式應當實作下列方法:extension, mime_type,
    encode 以及 decode。

    

module ActiveResource   module Formats    module Extend     module CSVFormat      extend self      def extension       'csv'      end      def mime_type       'text/csv'      end      def encode(hash, options = nil)       # 數據以新格式編碼并返回      end      def decode(csv)       # 數據以新格式解碼并返回      end     end    end   end  end  class User < ActiveResource::Base   self.format = ActiveResource::Formats::Extend::CSVFormat   ...  end

    若 HTTP 請求應當不擴展發送時,覆寫 ActiveResource::Base 的 element_path 及 collection_path 方法,并移除擴展的部分。

  class User < ActiveResource::Base   ...   def self.collection_path(prefix_options = {}, query_options = nil)    prefix_options, query_options = split_options(prefix_options) if query_options.nil?    "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"   end   def self.element_path(id, prefix_options = {}, query_options = nil)    prefix_options, query_options = split_options(prefix_options) if query_options.nil?    "#{prefix(prefix_options)}#{collection_name}/#{URI.parser.escape id.to_s}#{query_string(query_options)}"   end  end

    如有任何改動網址的需求時,這些方法也可以被覆寫。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临邑县| 新乡县| 军事| 英德市| 江陵县| 平阴县| 沭阳县| 颍上县| 留坝县| 涡阳县| 浏阳市| 大悟县| 枣庄市| 大田县| 大宁县| 介休市| 平顺县| 自贡市| 五莲县| 启东市| 蒲城县| 武穴市| 丹凤县| 全南县| 嘉黎县| 兴国县| 旬阳县| 东源县| 泸水县| 遵义县| 临泽县| 历史| 崇文区| 平谷区| 宁武县| 新宾| 阜宁县| 竹山县| 会宁县| 鸡东县| 平顶山市|