无法序列化嵌套的活动资源

时间:2012-01-20 14:54:07

标签: ruby activeresource

我开发了一个RESTful Web服务,它通过ActiveResource使用另一个RESTful Web服务(Proxmox Virtual Environment 2)。

PVE 2拥有大量嵌套资源。我目前正在尝试将PVE的存储和存储内容集成到我的应用程序中。

PVE的资源结构可以在http://pve.proxmox.com/pve2-api-doc/看到。

对于PVE 2,节点包含存储和存储具有内容(例如DVD ISO)。以下是我的有效资源:

node.rb:

class Node < ActiveProxmoxResource
  self.site = "https://127.0.0.1:8006/api2/json/"
  attr_accessor :headers

  def storages(scope = :all)
    storages =
      Storage.find(scope, :params => {:node_name => @attributes['name']})
    return storages
  end
end

storage_content.rb:

class StorageContent < ActiveProxmoxResource
  self.site = "https://127.0.0.1:8006/api2/json/nodes/:node_name/storage/:storage_name"
  self.element_name = "content"
  self.collection_name = "content"

  def storage
    storages = Storage.find(self.prefix_options[:storage_name])
    return storages
  end
end

storage.rb:

class Storage < ActiveProxmoxResource
  self.site = "https://127.0.0.1:8006/api2/json/nodes/:node_name"
  self.element_name = "storage"
  self.collection_name = "storage"
  attr_accessor :headers

  def storage_contents(scope = :all)
    storage_contents =
      StorageContent.find(scope, :params => {
      :node_name => self.prefix_options[:node_name],
      :storage_name => @attributes['storage']
    })
    return storage_contents
  end

  def node
    nodes = Node.find(self.prefix_options[:node_name])
    return nodes
  end
end

我无法序列化StorageContent实例。它适用于存储实例。以下是错误消息:

  

ArgumentError(参数太少):    app / controllers / storage_contents_controller.rb:15:index' app/controllers/storage_contents_controller.rb:14:in索引'

控制器如下所示:

class StorageContentsController < ApplicationController
  def index
    nodes = Node.find(:all)
    contents = []

    nodes.each do |n|
      n.storages.each do |s|
        s.storage_contents.each do |c|
          contents << c
        end
      end
    end

    respond_to do |format| # line 14
      format.xml {render :xml => contents} # line 15
    end
  end
end

我正在努力解决这个问题好几个小时,但仍然无法弄清楚我做错了什么(至少我做错了什么)。一些帮助会很好! :)

安托

PS:我希望我没有犯太多英语错误,因为我英语不流利。 :■

0 个答案:

没有答案