Forum: Ruby on Rails ActiveRecord: Attribute Setter for belongs_to relation attr

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-06-26 17:13
(Received via mailing list)
Hi,

I m trying to link into the process of setting an belongs_to attribute
in my model. Unfortunetly, it does not seem to be as easy as for
"normal" attributes.

I ve tried the following:
class Treatment < ActiveRecord::Base
  belongs_to :drug

  def drug=(new_value)
    'my stuff
    super new_value
  end

However, that does not work. Ive also tried self[:drug] = new_value...
However, that is also not working.

Any ideas?

Thanks a lot in advance.

--
Volker
Mark Reginald J. (Guest)
on 2007-06-26 19:55
(Received via mailing list)
removed_email_address@domain.invalid wrote:

>     super new_value
>   end
>
> However, that does not work. Ive also tried self[:drug] = new_value...
> However, that is also not working.

http://groups.google.com/group/rubyonrails-talk/br...

--
We develop, watch us RoR, in numbers too big to ignore.
This topic is locked and can not be replied to.