Forum: Ruby on Rails How to update two records ?

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.
A148ae0a643ff0975ae988c709ded57e?d=identicon&s=25 Tom Bernag (Guest)
on 2006-01-20 19:02
I have problem to update personaldata accessing with/from @user.
'@debug @user' shows that @user.personaldata attributes are properlly
modified, but '@user.save' saves only table users but not personaldatas
Is a problem with my associations? How to save personaldata with
@user.save ?


class User < ActiveRecord::Base
  has_one :personaldata
end

class Personaldata < ActiveRecord::Base
  belongs_to :user
end


class UserController < ApplicationController
 def update
  @user = User.find_by_username(params[:id], :include =>
[:personaldata])
  @user.attributes = params[:personaldata] # <- doesn't work
  #@user.personaldata.attributes = params[:personaldata]  # <- this way
it doesn'to work too

  if @user.save
    flash[:notice] = 'Updated'
    redirect_to :action => 'list'
  else
    render :action => 'new'
  end
 end
end
This topic is locked and can not be replied to.