If you had previously generated your User model with the rails generate draft:devise
command here are some steps you should take to resolve
navigate to /git
and make a commit.
In the db/migrate/
folder, look for the file with "create_devise_users" in the name and open it.
Replace the change method with the following:
def change
create_table :users do |t|
t.string :username
t.string :password_digest
# ...
# add any addiional columns for your table here
# the syntax is t.column_type :column_name
t.timestamps
end
end
You can add any other columns you had in your table with between the create_table
and the first end
keyword.
Next, replace the entire content of your user.rb
model file with this
class User < ApplicationRecord
end
Now open a new terminal and type
rails db:drop
then hit the enter key to remove all the tables in your database.
In the menu dropdown select
rails db:migrate
to recreate your tables, including the update User table.
We can follow the same steps we took in photogram-signin from here or copy from the photogram-bootstrap assignment.
-
Create the
users_controller.rb
and add actions to add theid
of the User to thesession
hash when they log in. -
Modify the
application_controller.rb
to force a user to sign in to use your app with abefore_action
. -
If you force a User to sign_in with a
before_action
make sure you exclude the actions you wrote to display the sign in form, the sign up form, the add Userid
tosession
action, and the action where you create a User.- something like:
skip_before_action :authenticate_user!, :only => [:session_form, :add_cookie, :registration_form, :create]
- something like:
-
Create a
current_user
helper method in theapplication_controller.rb
.
Make a git
commit so you never lose any of these changes.
If you need a reminder on any step there is the photogram-signin walkthrough video as a reference and we can also be available to walk you through the changes.
Yeah this looks great