Eric Goodwin
2006-Feb-03 07:48 UTC
[Rails] Saving a User Object while in the Address Controller
Hi, My saves are failing me and I can''t figure out why. I am trying to save an address id to a user object just after I create the address. This isn''t the exact code, but it shows what I am trying to do. class AddressesController < ApplicationController def create @address = Address.new(params[:address]) saved_address = @address.save @user = User.find(params[:id]) @user.address_id = @address.id saved_user = @user.save end end User.save keeps on returning false. Any ideas why? I can access different attributes of the user, so I know that the proper user is getting returned from the find. In my user class I have attr_accessible :address_id so I should be able to access it, shouldn''t I? Cheers, Eric -- Eric Goodwin ericgoodwin.com
Mikkel Bruun
2006-Feb-03 07:54 UTC
[Rails] Saving a User Object while in the Address Controller
Have you defined any realations between user and address??? just do user.adress =@address Mikkel On 2/3/06, Eric Goodwin <ruby@ericgoodwin.com> wrote:> > Hi, > My saves are failing me and I can''t figure out why. > I am trying to save an address id to a user object just after I create > the address. > This isn''t the exact code, but it shows what I am trying to do. > > class AddressesController < ApplicationController > def create > @address = Address.new(params[:address]) > saved_address = @address.save > > @user = User.find(params[:id]) > @user.address_id = @address.id > saved_user = @user.save > end > end > > User.save keeps on returning false. > Any ideas why? I can access different attributes of the user, so I know > that the proper user is getting returned from the find. > In my user class I have attr_accessible :address_id so I should be able > to access it, shouldn''t I? > > Cheers, > Eric > > -- > Eric Goodwin > ericgoodwin.com > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060203/de0176d8/attachment.html
Eric Goodwin
2006-Feb-03 08:03 UTC
[Rails] Saving a User Object while in the Address Controller
Hi Mikkel, I already has the relationships defined but I tried your code as well. It still won''t save. It''s quite bizarre. Thanks for the try. Eric Mikkel Bruun wrote:> Have you defined any realations between user and address??? > > just do user.adress =@address <mailto:=@address> > > Mikkel > > > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com > <mailto:ruby@ericgoodwin.com>> wrote: > > Hi, > My saves are failing me and I can''t figure out why. > I am trying to save an address id to a user object just after I > create > the address. > This isn''t the exact code, but it shows what I am trying to do. > > class AddressesController < ApplicationController > def create > @address = Address.new(params[:address]) > saved_address = @ address.save > > @user = User.find(params[:id]) > @user.address_id = @address.id <http://address.id> > saved_user = @user.save > end > end > > User.save keeps on returning false. > Any ideas why? I can access different attributes of the user, so I > know > that the proper user is getting returned from the find. > In my user class I have attr_accessible :address_id so I should > be able > to access it, shouldn''t I? > > Cheers, > Eric > > -- > Eric Goodwin > ericgoodwin.com <http://ericgoodwin.com> > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Eric Goodwin ericgoodwin.com
Mikkel Bruun
2006-Feb-03 08:09 UTC
[Rails] Saving a User Object while in the Address Controller
did the address get saved??? Mikkel On 2/3/06, Eric Goodwin <ruby@ericgoodwin.com> wrote:> > Hi Mikkel, > I already has the relationships defined but I tried your code as well. > It still won''t save. It''s quite bizarre. > Thanks for the try. > Eric > > Mikkel Bruun wrote: > > > Have you defined any realations between user and address??? > > > > just do user.adress =@address <mailto:=@address> > > > > Mikkel > > > > > > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com > > <mailto:ruby@ericgoodwin.com>> wrote: > > > > Hi, > > My saves are failing me and I can''t figure out why. > > I am trying to save an address id to a user object just after I > > create > > the address. > > This isn''t the exact code, but it shows what I am trying to do. > > > > class AddressesController < ApplicationController > > def create > > @address = Address.new(params[:address]) > > saved_address = @ address.save > > > > @user = User.find(params[:id]) > > @user.address_id = @address.id <http://address.id> > > saved_user = @user.save > > end > > end > > > > User.save keeps on returning false. > > Any ideas why? I can access different attributes of the user, so I > > know > > that the proper user is getting returned from the find. > > In my user class I have attr_accessible :address_id so I should > > be able > > to access it, shouldn''t I? > > > > Cheers, > > Eric > > > > -- > > Eric Goodwin > > ericgoodwin.com <http://ericgoodwin.com> > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > >------------------------------------------------------------------------ > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > -- > Eric Goodwin > ericgoodwin.com > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060203/23487acc/attachment.html
Eric Goodwin
2006-Feb-03 08:14 UTC
[Rails] Saving a User Object while in the Address Controller
No. I think it must be something to do with my User class. I have tried the same code but with a different class and it works. I am going to have a deeper look into my user class now and see if I can figure out why it won''t let itself be updated. Eric Mikkel Bruun wrote:> did the address get saved??? > > Mikkel > > > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com > <mailto:ruby@ericgoodwin.com>> wrote: > > Hi Mikkel, > I already has the relationships defined but I tried your code as well. > It still won''t save. It''s quite bizarre. > Thanks for the try. > Eric > > Mikkel Bruun wrote: > > > Have you defined any realations between user and address??? > > > > just do user.adress =@address <mailto:=@address> > > > > Mikkel > > > > > > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com > <mailto:ruby@ericgoodwin.com> > > <mailto:ruby@ericgoodwin.com <mailto:ruby@ericgoodwin.com>>> wrote: > > > > Hi, > > My saves are failing me and I can''t figure out why. > > I am trying to save an address id to a user object just after I > > create > > the address. > > This isn''t the exact code, but it shows what I am trying to do. > > > > class AddressesController < ApplicationController > > def create > > @address = Address.new(params[:address]) > > saved_address = @ address.save > > > > @user = User.find(params[:id]) > > @user.address_id = @address.id <http://address.id> > <http://address.id> > > saved_user = @user.save > > end > > end > > > > User.save keeps on returning false. > > Any ideas why? I can access different attributes of the > user, so I > > know > > that the proper user is getting returned from the find. > > In my user class I have attr_accessible :address_id so I should > > be able > > to access it, shouldn''t I? > > > > Cheers, > > Eric > > > > -- > > Eric Goodwin > > ericgoodwin.com <http://ericgoodwin.com> > <http://ericgoodwin.com> > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > <mailto:Rails@lists.rubyonrails.org> > <mailto:Rails@lists.rubyonrails.org > <mailto:Rails@lists.rubyonrails.org>> > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > >------------------------------------------------------------------------ > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > -- > Eric Goodwin > ericgoodwin.com <http://ericgoodwin.com> > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Eric Goodwin ericgoodwin.com
Joe Van Dyk
2006-Feb-03 10:43 UTC
[Rails] Saving a User Object while in the Address Controller
On 2/3/06, Eric Goodwin <ruby@ericgoodwin.com> wrote:> No. I think it must be something to do with my User class. I have tried > the same code but with a different class and it works. > I am going to have a deeper look into my user class now and see if I can > figure out why it won''t let itself be updated. > EricIf the user class has any validations or anything that fail, then the save of the user object will fail. Try looking at what user.errors.full_messages is after the save.> Mikkel Bruun wrote: > > > did the address get saved??? > > > > Mikkel > > > > > > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com > > <mailto:ruby@ericgoodwin.com>> wrote: > > > > Hi Mikkel, > > I already has the relationships defined but I tried your code as well. > > It still won''t save. It''s quite bizarre. > > Thanks for the try. > > Eric > > > > Mikkel Bruun wrote: > > > > > Have you defined any realations between user and address??? > > > > > > just do user.adress =@address <mailto:=@address> > > > > > > Mikkel > > > > > > > > > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com > > <mailto:ruby@ericgoodwin.com> > > > <mailto:ruby@ericgoodwin.com <mailto:ruby@ericgoodwin.com>>> wrote: > > > > > > Hi, > > > My saves are failing me and I can''t figure out why. > > > I am trying to save an address id to a user object just after I > > > create > > > the address. > > > This isn''t the exact code, but it shows what I am trying to do. > > > > > > class AddressesController < ApplicationController > > > def create > > > @address = Address.new(params[:address]) > > > saved_address = @ address.save > > > > > > @user = User.find(params[:id]) > > > @user.address_id = @address.id <http://address.id> > > <http://address.id> > > > saved_user = @user.save > > > end > > > end > > > > > > User.save keeps on returning false. > > > Any ideas why? I can access different attributes of the > > user, so I > > > know > > > that the proper user is getting returned from the find. > > > In my user class I have attr_accessible :address_id so I should > > > be able > > > to access it, shouldn''t I? > > > > > > Cheers, > > > Eric > > > > > > -- > > > Eric Goodwin > > > ericgoodwin.com <http://ericgoodwin.com> > > <http://ericgoodwin.com> > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > <mailto:Rails@lists.rubyonrails.org> > > <mailto:Rails@lists.rubyonrails.org > > <mailto:Rails@lists.rubyonrails.org>> > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > >------------------------------------------------------------------------ > > > > > >_______________________________________________ > > >Rails mailing list > > >Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > -- > > Eric Goodwin > > ericgoodwin.com <http://ericgoodwin.com> > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > >------------------------------------------------------------------------ > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > -- > Eric Goodwin > ericgoodwin.com > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Eric Goodwin
2006-Feb-04 18:45 UTC
[Rails] Saving a User Object while in the Address Controller
Thanks Joe, I ended up having a message in my errors due to a poorly written validate statement. Thanks for the help. Eric Joe Van Dyk wrote:>On 2/3/06, Eric Goodwin <ruby@ericgoodwin.com> wrote: > > >>No. I think it must be something to do with my User class. I have tried >>the same code but with a different class and it works. >>I am going to have a deeper look into my user class now and see if I can >>figure out why it won''t let itself be updated. >>Eric >> >> > >If the user class has any validations or anything that fail, then the >save of the user object will fail. > >Try looking at what user.errors.full_messages is after the save. > > > >>Mikkel Bruun wrote: >> >> >> >>>did the address get saved??? >>> >>>Mikkel >>> >>> >>>On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com >>><mailto:ruby@ericgoodwin.com>> wrote: >>> >>> Hi Mikkel, >>> I already has the relationships defined but I tried your code as well. >>> It still won''t save. It''s quite bizarre. >>> Thanks for the try. >>> Eric >>> >>> Mikkel Bruun wrote: >>> >>> > Have you defined any realations between user and address??? >>> > >>> > just do user.adress =@address <mailto:=@address> >>> > >>> > Mikkel >>> > >>> > >>> > On 2/3/06, *Eric Goodwin* <ruby@ericgoodwin.com >>> <mailto:ruby@ericgoodwin.com> >>> > <mailto:ruby@ericgoodwin.com <mailto:ruby@ericgoodwin.com>>> wrote: >>> > >>> > Hi, >>> > My saves are failing me and I can''t figure out why. >>> > I am trying to save an address id to a user object just after I >>> > create >>> > the address. >>> > This isn''t the exact code, but it shows what I am trying to do. >>> > >>> > class AddressesController < ApplicationController >>> > def create >>> > @address = Address.new(params[:address]) >>> > saved_address = @ address.save >>> > >>> > @user = User.find(params[:id]) >>> > @user.address_id = @address.id <http://address.id> >>> <http://address.id> >>> > saved_user = @user.save >>> > end >>> > end >>> > >>> > User.save keeps on returning false. >>> > Any ideas why? I can access different attributes of the >>> user, so I >>> > know >>> > that the proper user is getting returned from the find. >>> > In my user class I have attr_accessible :address_id so I should >>> > be able >>> > to access it, shouldn''t I? >>> > >>> > Cheers, >>> > Eric >>> > >>> > -- >>> > Eric Goodwin >>> > ericgoodwin.com <http://ericgoodwin.com> >>> <http://ericgoodwin.com> >>> > >>> > _______________________________________________ >>> > Rails mailing list >>> > Rails@lists.rubyonrails.org >>> <mailto:Rails@lists.rubyonrails.org> >>> <mailto:Rails@lists.rubyonrails.org >>> <mailto:Rails@lists.rubyonrails.org>> >>> > http://lists.rubyonrails.org/mailman/listinfo/rails >>> > >>> > >>> >------------------------------------------------------------------------ >>> > >>> >_______________________________________________ >>> >Rails mailing list >>> >Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> >>> >http://lists.rubyonrails.org/mailman/listinfo/rails >>> > >>> > >>> >>> >>> -- >>> Eric Goodwin >>> ericgoodwin.com <http://ericgoodwin.com> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>>------------------------------------------------------------------------ >>> >>>_______________________________________________ >>>Rails mailing list >>>Rails@lists.rubyonrails.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> >>> >>-- >>Eric Goodwin >>ericgoodwin.com >> >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Eric Goodwin ericgoodwin.com