Virtual Attributes?

1 view
Skip to first unread message

Jason Tuttle

unread,
Dec 12, 2008, 3:04:35 PM12/12/08
to rubyamf
Hi All,

I just ran into a problem with virtual attributes: I've got a model
with "password" and "password_confirmation" virtual attributes which
are defined in my Rails model:

attr_accessor :password_confirmation

def password
@password
end

def password=(pwd)
@password = pwd
create_new_salt
self.hashed_password = Foo.encrypted_password(self.password,
self.salt)
end

I've included them in my RubyAMF class mapping definition:

ClassMappings.register(
:actionscript => 'FooVO',
:ruby => 'Foo',
:type => 'active_record',
:attributes => ["id", "first_name", "last_name", "password",
"password_confirmation"])

Unfortunately, when I send a FooVO from Flex to Rails, all of the non-
virtual attributes get sent, but "password" and
"password_confirmation" are ignored.

Does anyone know how to tell RubyAMF to work with virtual attributes?

Thanks,

: )

Jason

Mike

unread,
Dec 14, 2008, 11:51:33 AM12/14/08
to rubyamf
You need to use :methods => ['password', 'password_confirmation']...
they're not attributes in an active record model sense.

See the bottom of this thread http://groups.google.com/group/rubyamf/browse_thread/thread/ec1ce30d5c21ecbb#

--Mike

Jason Tuttle

unread,
Dec 14, 2008, 12:28:25 PM12/14/08
to rub...@googlegroups.com
Perfect. -- Thanks a lot Mike!

: )

J

Jason Tuttle

unread,
Dec 14, 2008, 2:18:12 PM12/14/08
to rub...@googlegroups.com
Hi Mike,

Looks like I spoke too soon. -- What I'm trying to do is send a VO from Flex to Rails.

:methods => ['password', 'password_confirmation']... only seems to work when sending VOs in the other direction (i.e. from Rails to Flex).

If I add ['password', 'password_confirmation'] to either :methods or to :attributes in my RubyAMF Class Mapping, the result is the same: 'password', 'password_confirmation' are ignored by RubyAMF when sending VOs to Rails. All of the other attributes come through just fine. Only the virtual attributes are ignored.

Any help here would be greatly appreciated!

: )

J

On Sun, Dec 14, 2008 at 11:51 AM, Mike <msumm...@gmail.com> wrote:

Jason Tuttle

unread,
Dec 14, 2008, 4:29:08 PM12/14/08
to rub...@googlegroups.com
Ok, I think I've figured out both the problem and a possible solution. First, the problem appears to be in vo_helper.rb -- The get_vo_for_incoming method doesn't handle the :methods in the class mappings. However, if we add the following code to vo_helper.rb it will:

if mapping[:methods]
  mapping[:methods].each do |method|
    ruby_obj.send("#{method}=", obj.delete(method))
  end
end

Does anyone see a problem with this approach?

: )

Jason

On Sun, Dec 14, 2008 at 11:51 AM, Mike <msumm...@gmail.com> wrote:

Jason Tuttle

unread,
Dec 14, 2008, 4:47:59 PM12/14/08
to rub...@googlegroups.com
I just filed a bug with my patched copy of vo_helper.rb in case anyone is interested.

: )

Jason

Mike

unread,
Dec 15, 2008, 7:49:55 AM12/15/08
to rubyamf
Aha, good job.

I have to admit I prefer write_attribute for this job, programming by
configuration make me flashback to Java :-(


On Dec 14, 3:47 pm, "Jason Tuttle" <ja...@studio1h.com> wrote:
> I just filed a bug with my patched copy of vo_helper.rb in case anyone is
> interested.
>
> : )
>
> Jason
>
> On Sun, Dec 14, 2008 at 4:29 PM, Jason Tuttle <ja...@studio1h.com> wrote:
> > Ok, I think I've figured out both the problem and a possible solution.
> > First, the problem appears to be in vo_helper.rb -- The get_vo_for_incoming
> > method doesn't handle the :methods in the class mappings. However, if we add
> > the following code to vo_helper.rb it will:
> > if mapping[:methods]
> > mapping[:methods].each do |method|
> > ruby_obj.send("#{method}=", obj.delete(method))
> > end
> > end
>
> > Does anyone see a problem with this approach?
>
> > : )
>
> > Jason
>
> > On Sun, Dec 14, 2008 at 11:51 AM, Mike <msummer...@gmail.com> wrote:
>
> >> You need to use :methods => ['password', 'password_confirmation']...
> >> they're not attributes in an active record model sense.
>
> >> See the bottom of this thread
> >>http://groups.google.com/group/rubyamf/browse_thread/thread/ec1ce30d5...

Jarin Udom

unread,
Dec 19, 2008, 5:39:51 AM12/19/08
to rubyamf
I dislike programming by configuration too, but it is actually sort of
useful in this case to ensure that the VOs coming from Rails and the
ones enforced by frameworks like Cairngorm match up.

Jarin
Reply all
Reply to author
Forward
0 new messages