Skip to content

Important points about the construction of the application

Alejandra Rivera edited this page Jun 29, 2022 · 6 revisions

Validates

To validate that in the application, when creating a user, an email and a password are required; and when creating a task, a title is requested, I used validates, in the corresponding model.

app/models/user.rb

  validates :email, presence: true
  validates :password, presence: true

app/models/item.rb

  validates :title, presence: true

Devise Gem

To build the users in the application, I made use of the devise gem. This gem automatically generated the views and documents needed for its implementation.

rails generate devise:views
rails generate devise:install

One user can have many items

In the User model, I specified that a user can have many items.

app/models/user.rb

   has_many :items 

In the item model, I specified that the items belong to one user.

app/models/item.rb

  belongs_to :user

This allows the application to not display the tasks of a user other than the one logged in.

Clone this wiki locally