【发布时间】:2011-04-29 23:04:44
【问题描述】:
我正在开发一个 Rails 3 应用程序,该应用程序的容量很大。我正在使用 savon_model 和 ActiveModel 来生成与 ActiveRecord 等效项类似的行为。以下是我的代码:
class TestClass
include Savon::Model
include ActiveModel::Validations
# Configuration
endpoint "http://localhost:8080/app/TestService"
namespace "http://wsns.test.com/"
actions :getObjectById, :getAllObjects
attr_accessor :id, :name
def initialize(hash)
@id = hash[:id]
@name = hash[:name]
end
client do
http.headers["Pragma"] = "no-cache"
end
def self.all
h = getAllObjects(nil).to_array
return convert_array_hash_to_obj(h, :get_all_objects_response)
end
def self.find(id)
h = getObjectById(:arg0 => id).to_hash
return convert_hash_to_obj(h, :get_object_by_id_response)
end
private
def self.convert_array_hash_to_obj(arrayhash, returnlabel)
results = Array.new
arrayhash.each do |hash|
results << convert_hash_to_obj(hash, returnlabel)
end
return results
end
def self.convert_hash_to_obj(hash, returnlabel)
return TestClass.new(hash[returnlabel][:return])
end
end
好的,所以一切都按预期进行;值从 Web 服务中提取到页面上。不幸的是,当我查看在客户端生成的 html 时,存在一些问题。显示链接如下:
/testclasses/%23%3CTestClass:0xa814cb4%3E
而不是...
/testclasses/1
所以,我将对象(哈希?)打印到控制台以比较输出。
[#<System:0xa814cb4 @id="1", @name="CIS">]
而不是我认为应该是的......
[#<System id="1", name="CIS">]
我有三个问题:
1:打印出来的班级名称的十六进制后缀是什么
2:如何修改班级以匹配打印到控制台时所需的输出?
3:为什么前端链接(显示、编辑、删除)会损坏,是否有简单的修复方法?
非常感谢您抽出宝贵的时间并为垃圾代码/愚蠢的问题道歉。这是我的第一个 Ruby 或 Rails 应用程序!
加雷斯
【问题讨论】:
-
好吧,我得到了更多信息。我知道十六进制后缀是 object_id,但我仍然对为什么链接不起作用感到困惑。它与 route_keys 或 link_tos 有关吗?!我猜在这里,所以你能散发出的任何光芒都将不胜感激!谢谢加雷斯
标签: ruby-on-rails activerecord hash ruby-on-rails-3 activemodel