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?