濮阳杆衣贸易有限公司

主頁 > 知識庫 > Ruby on Rails中的ActiveResource使用詳解

Ruby on Rails中的ActiveResource使用詳解

熱門標簽:湖州u友防封電銷卡 滴滴外呼系統(tǒng) 徐州網(wǎng)絡外呼系統(tǒng)哪個好 常德電銷平臺外呼系統(tǒng)軟件價格 百度地圖標注自定義圖片 白銀外呼paas系統(tǒng) 電銷機器人廠商代理 高德地圖標注客服 地圖標注賺錢項目注冊

當 HTTP 響應是一個與存在的格式不同的格式時(XML 和 JSON),需要某些額外的格式解析,創(chuàng)一個你慣用的格式,并在類別中使用它。慣用的格式應當實作下列方法: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)
       # 數(shù)據(jù)以新格式編碼并返回
      end

      def decode(csv)
       # 數(shù)據(jù)以新格式解碼并返回
      end
     end
    end
   end
  end

  class User  ActiveResource::Base
   self.format = ActiveResource::Formats::Extend::CSVFormat

   ...
  end

    若 HTTP 請求應當不擴展發(fā)送時,覆寫 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

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

您可能感興趣的文章:
  • 關(guān)于Ruby on Rails視圖編寫的一些建議
  • 關(guān)于Ruby on Rails路由配置的一些建議
  • 詳解Ruby on Rails中的Cucumber使用

標簽:梧州 普洱 永州 張家界 三沙 荊門 公主嶺 遼寧

巨人網(wǎng)絡通訊聲明:本文標題《Ruby on Rails中的ActiveResource使用詳解》,本文關(guān)鍵詞  Ruby,Rails,中的,ActiveResource,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ruby on Rails中的ActiveResource使用詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于Ruby on Rails中的ActiveResource使用詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    玛纳斯县| 苏尼特右旗| 汾西县| 临武县| 双城市| 琼海市| 定日县| 远安县| 昔阳县| 宜君县| 宾阳县| 徐汇区| 个旧市| 盐城市| 明溪县| 宜州市| 德惠市| 建瓯市| 奇台县| 正镶白旗| 志丹县| 海原县| 琼中| 浦江县| 青州市| 闽清县| 永清县| 和林格尔县| 神农架林区| 兴文县| 宿松县| 长兴县| 万全县| 乡城县| 什邡市| 青浦区| 萍乡市| 思茅市| 娄烦县| 平定县| 农安县|