Re: Re: Problems with has_one - not saving association

Ben Jackson
2005-06-15T03:02:24Z

Sorry, I cut my code down to clarify... I am calling person.save, and
the user_id is still showing up as 0.

On Jun 14, 2005, at 11:21 PM, Demetrius Nunes wrote:

> Ben Jackson wrote:
>> Here are my models:
>> class Person < ActiveRecord::Base       has_one :user
>>     # class code...
>> class User < ActiveRecord::Base
>>     # class code...
>> And my controller:
>> class PersonController < ApplicationController
>>     def create
>>         unless logged_in?
>>             @user = User.new(@params[:user])
>>         else
>>             @user = @session[''user'']
>>         end
>>         @person = Person.new(@params[:person])
>>         @person.user = @user
>>         render_text @person.user_id
>>     end
>> end
>> @user.id is tracing out as expected, but the render_text call keep
>> spitting out 0. What am I doing wrong?
>
> You didn''t called @person.save. When you assign the user object to
> @person, it does not set the user_id until save is called.
>
> rgds
> Dema
> --
> http://dema.ruby.com.br - Rails development from a .NET perspective
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>