Ruby on rails 基于ActiveModel的类不会创建与ActiveRecord等效的结果相同的结果
我正在开发一个Rails 3应用程序,容量很大。我使用savon_模型和ActiveModel生成与ActiveRecord等价物类似的行为。下面是我的代码:Ruby on rails 基于ActiveModel的类不会创建与ActiveRecord等效的结果相同的结果,ruby-on-rails,activerecord,hash,ruby-on-rails-3,activemodel,Ruby On Rails,Activerecord,Hash,Ruby On Rails 3,Activemodel,我正在开发一个Rails 3应用程序,容量很大。我使用savon_模型和ActiveModel生成与ActiveRecord等价物类似的行为。下面是我的代码: class TestClass include Savon::Model include ActiveModel::Validations # Configuration endpoint "http://localhost:8080/app/TestService" namespace "http://wsns.t
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
而不是
/testclasses/1
因此,我将对象(散列?)打印到控制台以比较输出
[#<System:0xa814cb4 @id="1", @name="CIS">]
[#]
而不是我认为它应该是
[#<System id="1", name="CIS">]
[#]
我有三个问题:1:打印出来时,我的类名上的十六进制后缀是什么
2:打印到控制台时,如何修改类以匹配所需的输出?
3:为什么前端链接(显示、编辑、删除)会断开?是否有简单的修复方法? 非常感谢您抽出时间,并为垃圾代码/愚蠢的问题道歉。这是我的第一个Ruby或Rails应用程序 加雷斯
System
inspect
实例方法在控制台上操作输出to_param
实例方法来构建这些链接。如果要将类用作ActiveRecord替代品,则应实现此功能ActiveModel:Lint::Test
来验证ActiveModelAPI的哪些部分按预期工作
更多信息可以在这里找到:我有更多的信息。我知道十六进制后缀是object_id,但我仍然不明白为什么链接不起作用。这和路线钥匙或链接有关吗?!我在这里猜,所以您能提供的任何信息都将不胜感激!谢谢Gareth
[#<System id="1", name="CIS">]