Question

How to add a field such as address and other information of user that created by devise in registration place?

By using another table? or set a attr in model?

I have look through the documentation and found nothing, can anyone help me out?

Was it helpful?

Solution

You can either create separate models/migrations for additional fields and link them together (especially addresses go well in a model) or you add the fields to the devise migration directly. This is a devise migration I use for a small University project:

def self.up
  create_table(:students) do |t|
    t.database_authenticatable :null => false
    t.recoverable
    t.rememberable
    t.trackable
    # t.confirmable
    # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
    # t.token_authenticatable
    t.string :name
    t.string :studentNumber
    t.references :faculty
  t.timestamps
end

And the related line in the model:

attr_accessible :studentNumber, :email, :name, :faculty, :password, :password_confirmation
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top