Jan 27
Sending Typed Value Objects from Flex to Rails using WebORB and the [RemoteClass] metadata tag
In Part 2 of the tutorials that I have been writing about the Issue Tracker sample app (view, source) I discussed how you can Get Typed Objects from Rails using [RemoteClass]. Now, with the latest version of WebORB, it is also possible send typed objects from Flex to Rails.
This means that you no longer have to use untyped objects or XML to send values from Flex to Rails. Now you can just pass typed value objects back and forth between Flex and Rails.
So now, in the Issue Tracker sample app, when an IssueVO is sent from Flex to Rails, because it is mapped to the Issue ActiveRecord class (using the process that is explained in Part 2), it automatically gets converted to an Issue ActiveRecord instance. If the value of the id attribute on the IssueVO matches an existing Issue ActiveRecord then WebORB will return that object, otherwise it will create a new ActiveRecord instance.
This makes it possible to simplify the updateIssue method as follows:
def updateIssue(issue)
issue.save
end

January 27th, 2007 at 3:54 pm
Derek – you are really doing a great job of putting WebORB through its paces – and publishing the result. Great work!
February 1st, 2007 at 12:07 am
Cool. Does WebOrb hold on to a reference to any Issue object sent to Flex? Or do we need to keep a reference around to it (on the rails side) in order for there to be “an existing issue ActiveRecord” ?
Thanks.
February 1st, 2007 at 2:06 am
Frank – WebORB checks the database to see if the object exists by using ActiveRecord’s exists? method. So you do not have to keep your own reference to it on the Rails side.
The code looks something like this:
ActiveRecord.exists?(@flex_object_attributes[ActiveRecord.primary_key])
Where flex_object_attributes is a hash that contains all of the values from the object that is sent over from Flex.
Derek
February 2nd, 2007 at 8:43 am
Thanks Derek! Your article is greatly helpful.
Is that possible sending ArrayCollection object from Flex to Ruby via WebORB? Or all I could do is ArrayCollection.toArray() ,then send it?
Thanks again. You are great.
Robert
February 3rd, 2007 at 8:53 pm
Hi Robert,
Your best bet would be to send covert the ArrayCollection to an Array first, and then send it over to Rails.
If you try to send an ArrayCollection you will get an error because there is no ArrayCollection class in Rails/Ruby and Rails will not know what to do with it.
February 5th, 2007 at 2:55 am
[...] Thanks Derek. So I must call toArray() while sending ArrayCollection data. you can read the reply here. [...]
February 25th, 2007 at 7:05 am
Derek,
I noticed your reference to the simplified version of the updateIssue method, but I did not find it implemented that way in the IssueTracker2 code. Do I have an old version?
Martin
February 25th, 2007 at 8:32 pm
Hi Martin,
No, I have been working on an update to this app that will include this change and some other features, but it’s not quite done yet. I hope to have it done by next month.
Best,
Derek
April 16th, 2007 at 9:39 pm
i’m sending arraycollection to Ruby from Flex and i’m receiving arraycollection directly to Flex!
Ruby will receive arraycollection if you map it in the file weborb-config.xml:
flex.messaging.io.ArrayCollection
ObjectProxy
weborb.v3types.ObjectProxy
And if you want send arraycollection from Ruby to Flex is a little harder…
Edit the file message_writer.rb.
Replace line->
write_array_method = writer_class.method :write_array
by
write_array_method = writer_class.method :write_array_collection
And this function to the same file
def MessageWriter.write_array_collection( data_object, formatter )
formatter.begin_write_array_collection()
write_array(data_object, formatter)
end
and finally edit amfv3_formatter.rb and add this function:
def begin_write_array_collection()
@writer.write_byte( 0×0a )
@writer.write_byte( 0×07 )
@writer.write_utf( “flex.messaging.io.ArrayCollection”, true )
end
Now all array from Ruby will be send as ArrayCollection in Flex.
I think is working well
May 3rd, 2007 at 8:46 am
hi,
as u said i’m able to configure ruby for arraycollection. but can you tell me how to store the array collection which comes from a VO object to the ruby function in the database. i’m new to ruby and i don’t find an example for this.i’ll be greatful; if can send me a sample code of rails function which recieves the arraycollection from the flex and store in a database
Thanks,
Shajahan
June 21st, 2007 at 2:55 am
I am investigating the ruby version of weborb and I am running into an issue. I am sending a mapped class that contains an array of another mapped class to rails for saving. The problem I am having is by the time my flash class makes it to the rails method it has already decided to look up the data for the items in the array and ends up overwriting the data in the original argument from flash. So basically it ends up not getting the new data and running an update with the same data.
Flash class:
class Foo{
public var id:uint;
public var blahArray:Array;
}
class Blah{
public var id:uint;
public var name:String;
}
So if the the blahArray contains items that already have an id, they get looked up when I pass a foo instance to be saved before I get to call save with the new data for name. I have confirmed this by looking at the sql that runs. Am I missing something, to me this defeats the purpose of even using this stuff. I would appreciate any suggestions at all.
Thanks!