Currently I have the Devise gem in Rails, I want to add more registration fields in a tutorial that I found on the internet I already added the field
class DeviseCreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
t.string :user_role
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
And I run rails db:migration but I can't see the field in the postgresql database
You can add more fields like for any other model ( https://guides.rubyonrails.org/active_record_migrations.html ) using migrations for example.
When executing
rake db:migrate
these fields they will be added to the tables created by devise.The second thing to keep in mind is that you will need to modify the record views to support these new fields, for this you must obtain the plan views with
rails generate devise:views
which they will be created under the routeapp/views/devise/
.In the parents file
app/views/devise/registrations/new.html.erb
add the new fields to the form.Later you must add a custom controller to support the protection to the new fields.
And finally redirect the routes for the sign_up views to your new controller. (
routes.rb
)And voila, with that you should have your new registration form.
Create another migration where you add the new attributes to the users table, that's all