Notifications
You’re not receiving notifications from this thread.
Devise User with separate Profile
Hi,
i am using Devise and i want to a separate profile for each user with additional informations like address, phone, mobile, ...
After Signup, the user should be forced to fill out his profile.
right now i have the standard devise user model and the profile model.
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :inet
# last_sign_in_ip :inet
# confirmation_token :string
# confirmed_at :datetime
# confirmation_sent_at :datetime
# unconfirmed_email :string
# failed_attempts :integer default(0), not null
# unlock_token :string
# locked_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
class User < ActiveRecord::Base
has_one :profile, dependent: :destroy
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
# == Schema Information
#
# Table name: profiles
#
# id :integer not null, primary key
# user_id :integer
# title :string
# first_name :string
# last_name :string
# street :string
# zip :string
# city :string
# country :string
# phone :string
# mobile :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Profile < ActiveRecord::Base
belongs_to :user
validates :title, :first_name, :last_name, :country, :mobile, presence: true
end
Any hint how i can start?
Hey Benny,
You can redirect after sign up the a ProfilesController new action. If you want to enforce it, you can set a before_action :require_profile!
that redirects users to that until they have created one. All sorta depends on how you want to the user experience to be like. Just make sure your require_profile
before_action gets skipped on the new and create methods for the ProfilesController and that should do the trick!