Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create controllers, models, and simple views using devise gem #4

Merged
merged 6 commits into from
Dec 13, 2024

Conversation

IvanRuskevych
Copy link
Collaborator

time: 2,5 h

  1. install devise gem & config it
  2. create user model & controllers

Comment on lines 8 to 9
# validates :password, length: { minimum: 6, maximum: 20 }, presence: true, uniqueness: {case_sensitive: false}
# validates :password_confirmation, presence: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validations should be used on these

Copy link
Collaborator Author

@IvanRuskevych IvanRuskevych Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the recommendations!

  1. I removed validates for password because Devise has it
  2. I write validates for email & password_confirmation

# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = '706ef6afa1a8dbc795dc5806bf6bd7241c0b45ef40d92db81e067b1b7a3f5528f3075de9f7d92fc172d5e4d2b310303843bf54e9d2ba1f116fb5208a560979b8'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see this comment here

Copy link
Collaborator Author

@IvanRuskevych IvanRuskevych Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the recommendations!

  1. I put config.secret_key to config/environments/test.rb & to config/environments/development.rb

# :confirmable

# validates :password, length: { minimum: 6, maximum: 20 }, presence: true, uniqueness: {case_sensitive: false}
# validates :password_confirmation, presence: true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea to add a validation for the email to ensure it follows a standard format. I recommend using the built-in regular expression URI::MailTo::EMAIL_REGEXP, which is a best practice for validating email correctness in Ruby on Rails, as it follows the standard format and simplifies the code. You should also add a validation for email uniqueness with case sensitivity to avoid duplicates.

validates :email, presence: true, uniqueness: { case_sensitive: true }, format: { with: URI::MailTo::EMAIL_REGEXP, message: "must be a valid email format" }

Don't forget about tests. You should write corresponding RSpec tests to ensure that the validations work correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the recommendations!

  1. I removed the validations for password because Devise already handles them.
  2. I added validations for email and password_confirmation.
  3. I plan to create tests in one of the upcoming PRs. Is that okay, or should I include them in this PR with the current implementation of the User model?

@rogergraves rogergraves merged commit 0e58929 into master Dec 13, 2024
0 of 2 checks passed
@IvanRuskevych
Copy link
Collaborator Author

Hi Team,

I’ve addressed the feedback provided earlier and updated the pull request accordingly. Could you please take another look when you have time? Let me know if there’s anything else I should improve.

Thanks in advance!

@IvanRuskevych IvanRuskevych deleted the users-model branch December 23, 2024 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants