I'm working on a Rails 6 application where I was separating the User and Profile models. This caused some issues as shown in this post Rails 6: Only one profile per user should be created I'm using Devise for authentication and decided to add a users controller. I want to be able to User the user model as a profile and that Devise takes care of the sign_up, sign_in and the creation of the user.
I created the user's controller to show, edit, update and destroy and would use this as the "profile".However, I'm confused about the following. How to make Devise work with the users_controller that inherits from ApplicationRecord wouldn't this 2 conflict?
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Profile information
t.string :full_name
t.string :city
t.string :bio
t.timestamps null: false
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
I added the other fields into the DeviseCreateUsers migration. Should I create a separate create_users_migration? I would like for a user to sign up with email and password and not necessarily need the fields :full_name,:city, :bio to create the instance of User.
routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions'
}
resources :users, only: [:show, :edit, :update, :destroy]
resources :posts do
resource :comments, only: %i[show new create edit update]
end
end
When I followed the Devise documentation: https://github.com/plataformatec/devise#configuring-controllers I'm a bit confused about the followin. I run the command
$ rails generate devise:controllers users
Does the documentation is unclear as to whether one should add the views of log_in,sign_up those forms into the users folder or only new.html.erb form devise/sessions which is the only template that is generated.
