User Model
Explore how to generate a User model using Devise in Ruby on Rails, establish a one-to-many relationship between users and links, and add the user_id attribute to links. Understand the steps to migrate your database and optimize queries with indexed foreign keys to manage user-associated data effectively.
We'll cover the following...
Now that you have your Link structure set up, you need to set up your User structure.
To do this, you will need to do the following:
- Create a
Usermodel to handle user data - Associate
UserandLink - Add
user_idattribute/column toLink
Generating the User model
Devise
To generate the user model, you will use a Ruby gem called Devise. Devise provides Rails with a simple way to add user authentication to applications.
You will get Devise to dump all its views to our Rails app. By default, these views are contained within the gem itself and thus are non-modifiable.
You will run the following command:
rails g devise:views
This will create a devise folder in app/views/. ...