Extra attributes

1 view
Skip to first unread message

Paulo Fernando Larini

unread,
Nov 10, 2008, 6:35:30 PM11/10/08
to rub...@googlegroups.com
Hi, how can I send an extra attribute (not defined in the fisical
table) to flex ?

Mike

unread,
Nov 11, 2008, 7:41:24 AM11/11/08
to rubyamf
If you're wanting to add an attribute to a model object you can use
write_attribute:


On Nov 10, 5:35 pm, "Paulo Fernando Larini" <pflar...@gmail.com>
wrote:

Paulo Fernando Larini

unread,
Nov 11, 2008, 8:39:31 AM11/11/08
to rub...@googlegroups.com
I thing that it is not the case. Look, I have a model like this:

class Person < ActiveRecord::Base

attr_accessor :age

end

or

class Person < ActiveRecord::Base

def age
#calculate the age here
.....
end

end


When sending this objet to flex, I need that the the "age" value goes too.


.


2008/11/11 Mike <msumm...@gmail.com>:

Mike

unread,
Nov 11, 2008, 10:26:40 AM11/11/08
to rubyamf
Correct, using attr_* doesn't work, it doesn't set an ActiveRecord
attribute.

Look-up write_attribute in ActiveRecord::Base
http://ar.rubyonrails.org/classes/ActiveRecord/Base.html

This took about 1/2 a day to figure-out the first time I ran into it :-
(


On Nov 11, 7:39 am, "Paulo Fernando Larini" <pflar...@gmail.com>
wrote:
> I thing that it is not the case. Look, I have a model like this:
>
> class Person < ActiveRecord::Base
>
> attr_accessor :age
>
> end
>
> or
>
> class Person < ActiveRecord::Base
>
> def age
> #calculate the age here
> .....
> end
>
> end
>
> When sending this objet to flex, I need that the the "age" value goes too.
>
> .
>
> 2008/11/11 Mike <msummer...@gmail.com>:

Paulo Fernando Larini

unread,
Nov 11, 2008, 10:48:38 AM11/11/08
to rub...@googlegroups.com
Hey Mike, I get it to work now! Works perfectly!

Thank you.


2008/11/11 Mike <msumm...@gmail.com>:

Jarin Udom

unread,
Nov 11, 2008, 12:31:15 PM11/11/08
to rubyamf
You could also add a method in the ClassMappings, like so:

ClassMappings.register(
:actionscript => "com.myapp.vo.PersonVO",
:ruby => "Person",
:type => "active_record",
:attributes => ["id", "name", "email"],
:methods => ["age"])

On Nov 11, 7:48 am, "Paulo Fernando Larini" <pflar...@gmail.com>
wrote:
> Hey Mike, I get it to work now! Works perfectly!
>
> Thank you.
>
> 2008/11/11 Mike <msummer...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages