Hi!
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.
Thanks.
Anjan