RubyAMF v2 - Tries to set associations which are not sent from Flex

Skip to first unread message


Oct 15, 2011, 7:06:36 AM10/15/11

I have been using the rubyamf_plugin successfully with my project for about a year now. Since RubyAMFv2 is supposed to replace the old plugin, I decided to port my app to the new syntax of the v2 gem.

I did all the required changes and got it to work (partially). I have run into a problem which may deal with a difference in behavior between the old and new versions of RubyAMF. I will attempt to describe this below.

In my project, the parameters of my AMF calls from Flex are not always just integers or strings. The demo app only shows parameters of integer type. I send model objects as parameters too (for example a "blog" object). This model object will NOT necessarily have ALL its properties and associations set. Using the previous rubyamf_plugin, when such a model object is received by my Rails action, only those properties and associations which the Flex object had, would be set on the deserialized Rails object. Then, I read the required (relevant) properties and / or associations and saved them to the DB.

In RubyAMFv2, this does not seem to work. RubyAMFv2 seems to expect to find ALL parameters and associations on every Flex object it receives. When it doesn't find one, it throws an exception. I think this is undesirable behavior.

I think the problem is near here: line 67 - 70 in the lib/rubyamf/rails/model.rb:
# Set attributtes
# warhammerkid: Should we be setting associations some other way (not attributes)?
rubyamf_set_non_attributes attrs, base_attrs
self.send(:attributes=, attrs)

The first 11 lines of the backtrace of the error is below. "papers" is an association that I am NOT sending from Flex.

"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/gems/activerecord-3.0.10/lib/active_record/associations/association_collection.rb:354:in `replace'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/gems/activerecord-3.0.10/lib/active_record/associations.rb:1515:in `papers='",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:120:in `send'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:120:in `rubyamf_set_non_attributes'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:116:in `each'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:116:in `rubyamf_set_non_attributes'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/rails/model.rb:69:in `rubyamf_init'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/class_mapping.rb:201:in `populate_ruby_obj'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:42:in `populate_from_stream'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:42:in `handle_amf'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:29:in `call'"

Please let me know if you need any other information. I would appreciate any assistance to solve this problem.



Oct 15, 2011, 1:06:25 PM10/15/11
to rubyamf
Hi Anjan,

Objects can be sent down as parameters as well as is the case in the
demo for the more verbose parameter mapping format:

map_amf :controller => "BlogsController", :action =>
"create", :params => [:blog]

Can you paste in you mapping for the paper class and any other
affected classes to take a look at so I could have a better picture?
Also, are you using rubyamf_config.rb or are you using in model




Oct 15, 2011, 1:23:49 PM10/15/11
to rubyamf

This passes down a Blog object with no posts association:

map_amf :controller => "BlogsController", :action =>
"update", :params => [:blog]

So, if you check the demo, the Blog model that is referenced in the
above parameter mapping does not pass down (uses [transient] tag in
the AS class) the posts association and there is no problem.

Thus, I suspect something else is going on for you..



Oct 15, 2011, 1:24:19 PM10/15/11
to rubyamf

Bug reports should be logged on github at
to keep the list clean and to make it easier to manage the solution.
I've created a bug for this issue at
for tracking.

> "/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144 d47/lib/rubyamf/request_parser.rb:29:in


Oct 16, 2011, 7:03:35 AM10/16/11

I wasn't completely sure if it was a bug or whether I was doing something wrong. So, I wanted to clarify that here first before opening a ticket.

Thank you for the quick response. I have updated the ticket on GitHub.


Reply all
Reply to author
0 new messages