Forum: Ruby on Rails update multiple model in one form

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.
D7b2632679975d1175b449ca015b918f?d=identicon&s=25 Johny ben (johny)
on 2008-12-23 11:15
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
<h1>Editing user</h1>

<%= error_messages_for :user %>

<% form_for(@user) do |f| %>

<p>
    <b>Name</b><br />
    <%= f.text_field :login %>
  </p>

  <p>
    <b>Email</b><br />
    <%= f.text_field :email %>
  </p>

   <p>
    <%= f.submit "Update" %>
  </p>
<% end %>

my problem, how to add the lastname and firstname on the form and update
the model profile?and what the method update?
This topic is locked and can not be replied to.