Hash from Flex

Hi,

Im new to rails and trying to pass a hash, from my flex application to
my rails app.

My flex application calls a rails service

def updateScorecards(id, scorecard)

puts “im in update scorecards2”
puts pp scorecard

@update_scorecard = Scorecard.find(id , :include => :kpis)
puts pp @update_scorecard

end

Model:

class Scorecard < ActiveRecord::Base
has_and_belongs_to_many :kpis
end

im using pp to write out the params, so we see what happens. Now to my
questions, how do i update my @update_scorecard with values from
scorecard param
@update_scorecard.update_attributes gives me unified_strings! error

Help appriciated!

Debug from this is:

im in update scorecards2
[#<NamedObject:0x2907b68
@anonymous_object=
{“name”=>“FirstScoreCard”,
“id”=>1,
“kpis”=>
[#<NamedObject:0x2904f58
@anonymous_object=
{“name”=>“Generated.Kpi1”,
“unit”=>“something”,
“id”=>19,
“description”=>nil},
@object_name=“com.bsc.vo.Kpi”>,
#<NamedObject:0x2903248
@anonymous_object=
{“name”=>“Generated.Kpi2”,
“unit”=>“something”,
“id”=>20,
“description”=>nil},
@object_name=“com.bsc.vo.Kpi”>],
“view_id”=>1},
@object_name=“com.bsc.vo.Scorecard”>,
#<NamedObject:0x29059e4
@anonymous_object=
{“name”=>“SecondScoreCArd”, “id”=>2, “kpis”=>[], “view_id”=>1},
@object_name=“com.bsc.vo.Scorecard”>]
nil
#<Scorecard:0x27953c0
@attributes={“name”=>“FirstScoreCard”, “id”=>“1”, “view_id”=>“1”},
@kpis=
[#<Kpi:0x27948e4 @attributes={“name”=>“Generated.Kpi1”,
“unit”=>“something”, “id”=>“19”, “description”=>nil}>, #<Kpi:0x27944fc
@attributes={“name”=>“Generated.Kpi2”, “unit”=>“something”, “id”=>“20”,
“description”=>nil}>]>

update_attributes expects a proper hash. You’re handing it a
NamedObject. I’m not exactly certain what that is, but can you
convert it into a hash and then pass it into update_attributes?

On Mar 13, 12:36 am, Kvark D. [email protected]

Yo and thanks,

How do a proper hash look?

when you inspect it, it should look something like:

puts h.inspect

=> {“c”=>3, :a=>1, :b=>2}

not like

puts obj.inspect

=> #<RandomClass:0xb7c1f324 @inst={“c”=>3, :a=>1, :b=>2}>

Check the documentation for NamedObject and see if you can find some
way to have it return a hash. If there is none, you can grab the
anonymous_object instance variable directly:

hash = named_obj.instance_eval { @anonymous_object }

… with the understanding that if NamedObject’s implementation
changes in the future, your method might break.

On Mar 13, 4:01 am, Kvark D. [email protected]