views:

300

answers:

1

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?

A: 

We had the same problem, the only solution we found was to not pass Flex objects to Rails that have associations.