# Update multiple model in one form

**URL:** <https://www.ruby-forum.com/t/update-multiple-model-in-one-form/156244>\
**Category:** Rails\
**Created:** [December 23, 2008, 11:15am UTC](https://www.ruby-forum.com/t/update-multiple-model-in-one-form/156244 "2008-12-23T11:15:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@johny](https://www.ruby-forum.com/u/johny)\
**Post date:** [December 23, 2008, 11:15am UTC](https://www.ruby-forum.com/t/update-multiple-model-in-one-form/156244/1 "2008-12-23T11:15:22Z")

</div>

my project works like this the user will sign up first.after sign up  
he/she will edit his profile.I use restful authentication plugins for  
sign up.  
model  
class User \< ActiveRecord::Base  
has\_one :profile  
end

class Profile \< ActiveRecord::Base  
belongs\_to :user  
end

user controller  
def create  
cookies.delete :auth\_token  
@user = User.new(params[:user])  
@user.save

@profile = Profile.new  
@profile.user\_id = @user.id  
@profile.save  
end  
def edit  
@user = User.find(params[:id])  
end

migration  
class AddProfileTable \< ActiveRecord::Migration  
def self.up  
create\_table :profiles do |t|  
t.string :lastname  
t.string :firstname  
t.integer :user\_id

```
end

```

end

def self.down  
remove\_table :profiles  
end  
end  
edit form

# Editing user

\<%= error\_messages\_for :user %\>

\<% form\_for(@user) do |f| %\>

**Name**  
 \<%= f.text\_field :login %\>

**Email**  
 \<%= f.text\_field :email %\>

\<%= f.submit "Update" %\>

\<% end %\>

my problem, how to add the lastname and firstname on the form and update  
the model profile?and what the method update?
