将 AMF 对象从 Flex 发送到 Rails 会损坏关联模型
我们正在开发一个使用 Flex 和 Rails 以及 WebORB。 一切都很好,直到我们开始将前端和后端捆绑在一起。
我们创建了一个用于与用户交互的服务和另一个用于会话的服务。
SessionService.rb
class SessionService
def view_session
session = RequestContext.get_session
if session[:user_id]
user = User.find_by_id(session[:user_id], :include => [:contact, {:roles => :permissions}])
else
user = User.find_by_username("anonymous", :include => [:contact, {:roles => :permissions}])
end
user
end
end
UserService.rb
class UserService
def register_user user
user.save
session = RequestContext.get_session
session[:user_id] = user.id
RequestContext.set_session session
return true
end
end
User.as
package com.XXX.XXXXX.vo
{
[Bindable]
[RemoteClass(alias="com.XXX.XXXXX.vo.User")]
public class User
{
...
public var roles:Array;
...
}
}
当使用 Flex 调用任何方法时,一切正常,直到 register_user
调用传入的 User 对象。创建用户并更新会话,问题是此后调用的任何方法都会产生副作用,即 User.find(XX).roles[XX].skip_time_zone_conversion_for_attributes
现在为零,这会导致 activerecord/lib/activerecord/attribute_methods.rb
中的 create_time_zone_conversion_attribute?
在尝试调用 include?
时失败> 关于它。
由于在调用 method_missing
时调用 create_time_zone_conversion_attribute?
,因此直接访问任何属性都会导致此错误。 除了 :include => 之外,这不会成为问题。 [..., :roles...]
导致角色被序列化到 AMF 当它尝试序列化属性时,它会失败。
根据我在 attribute_methods.rb
中收集的信息,应该不可能在实例中更改 skip_time_zone_conversion_for_attributes
(Role.skip_time_zone_conversion_for_attributes = []
,如应该是)但我有一种感觉,WebORB 正在绕过这个并强行将其更改为零。
我们已经转而传递非模型类,但这不是我们想要的。
是否有可能找出 WebORB 中的哪些代码正在更改模型的所有实例的 skip_time_zone_conversion_for_attributes
而不是模型类本身?
We are working on a project that uses Flex and rails with WebORB. Everything was fine and dandy until we started tying the frontend and backends together.
We created a service for interacting with users and another for the session.
SessionService.rb
class SessionService
def view_session
session = RequestContext.get_session
if session[:user_id]
user = User.find_by_id(session[:user_id], :include => [:contact, {:roles => :permissions}])
else
user = User.find_by_username("anonymous", :include => [:contact, {:roles => :permissions}])
end
user
end
end
UserService.rb
class UserService
def register_user user
user.save
session = RequestContext.get_session
session[:user_id] = user.id
RequestContext.set_session session
return true
end
end
User.as
package com.XXX.XXXXX.vo
{
[Bindable]
[RemoteClass(alias="com.XXX.XXXXX.vo.User")]
public class User
{
...
public var roles:Array;
...
}
}
When calling any method with Flex, everything works fine until register_user
is called with an User object being passed in. The user is created and the session is updated, what goes wrong is that any method calls after this have a side effect that User.find(XX).roles[XX].skip_time_zone_conversion_for_attributes
is now nil, which causes create_time_zone_conversion_attribute?
in activerecord/lib/activerecord/attribute_methods.rb
to fail when trying to call include?
on it.
And since create_time_zone_conversion_attribute?
is called when method_missing
is called, direct access to any attribute causes this error. This wouldn't be a problem except for the :include => [..., :roles...]
which causes the roles to be serialied into AMF and when it tries to serialize the attributes, it bombs out.
From what I gather in attribute_methods.rb
, it should not be possible to change skip_time_zone_conversion_for_attributes
in an instance (Role.skip_time_zone_conversion_for_attributes = []
, as it should be) but I have a feeling that WebORB is bypassing this and forceibly changing it to be nil.
We have switched to passing non model classes, but this is not what we want.
Would it possible to find out what code in WebORB is changing skip_time_zone_conversion_for_attributes
for all instances of a model but not the model class itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们遇到了同样的问题,我们找到的唯一解决方案是不将 Flex 对象传递给具有关联的 Rails。
We had the same problem, the only solution we found was to not pass Flex objects to Rails that have associations.