Most likely your status is being referenced as a local method
variable. Try doing this:
self.status = Status.find(2)
That should do it. If not, you could always do this:
update_attribute("status_id", 2)
Not quite as pretty, but effective.
On 10/25/05, Chris Hall
<christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''m trying to do the following but it doesn''t seem to
work the way I''m
> expecting
>
> class Status < ActiveRecord::Base
> has_many :items
> end
>
> class Thing < ActiveRecord::Base
> has_many :items
> belongs_to :foo
> end
>
> class Foo < ActiveRecord::Base
> has_many :things
> end
>
> class Item < ActiveRecord::Base
> belongs_to :status
> belongs_to :thing
>
> def do_this(new_foo)
> status = Status.find(2)
> thing.foo = new_foo
> save
> end
> end
>
> now what i am expecting is that the item.status_id will be changed to
> reflect the id of the new status and item.thing.foo_id will be changed to
> reflect id of new_foo object, but this isn''t the case.
>
> what I am doing wrong here?
>
> Chris
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>