-
Notifications
You must be signed in to change notification settings - Fork 77
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
[BE]Signup validations #70
Changes from 1 commit
c4f09a9
56dbe0a
5f6b24c
dc1ca9e
e0a7af4
9d874c4
2b4dd4d
a4d3a7f
2ebf4c2
eb2ad09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Users::RegistrationsHelper | ||
def error_message_on(object, method) | ||
return unless object.respond_to?(:errors) && object.errors.include?(method) | ||
error = field_error(object, method) | ||
def error_message_on(resource, attribute) | ||
return unless resource.respond_to?(:errors) && resource.errors.include?(attribute) | ||
error = field_error(resource, attribute) | ||
|
||
content_tag(:div, error, class: "tracking-wider block text-xs font-semibold text-red-600") | ||
end | ||
|
||
def error_message_class(object, method) | ||
if object.respond_to?(:errors) && object.errors.include?(method) | ||
def error_message_class(resource, attribute) | ||
if resource.respond_to?(:errors) && resource.errors.include?(attribute) | ||
"rounded tracking-wider appearance-none border border-red-600 block w-full px-3 py-2 bg-miru-gray-100 h-8 shadow-sm font-semibold text-xs text-miru-dark-purple-1000 focus:outline-none focus:ring-red-600 focus:border-red-600 sm:text-base" | ||
else | ||
"rounded tracking-wider appearance-none border border-gray-100 block w-full px-3 py-2 bg-miru-gray-100 h-8 shadow-sm font-semibold text-xs text-miru-dark-purple-1000 focus:outline-none focus:ring-miru-gray-1000 focus:border-miru-gray-1000 sm:text-base" | ||
end | ||
end | ||
|
||
private | ||
def field_error(object, method) | ||
object.errors[method].first | ||
def field_error(resource, attribute) | ||
resource.errors[attribute].first | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,16 +101,17 @@ class User < ApplicationRecord | |
|
||
validates :first_name, :last_name, | ||
presence: true, | ||
format: { with: /\A[a-zA-Z]+\z/, message: "First and last name must only contain letters" } | ||
format: { with: /\A[a-zA-Z]+\z/ } | ||
validates :first_name, :last_name, length: { maximum: 50 } | ||
validates :email, format: { with: /^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, multiline: true } | ||
|
||
# Include default devise modules. Others available are: | ||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :validatable, | ||
:trackable, :confirmable | ||
|
||
validates :email, format: { with: /^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, multiline: true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can replace the regex with devise's default regex inside devise.rb There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thanks for the tip @keshavbiswa . I was actually looking to override devise's default email validation since it's weaker and validates strings such as |
||
|
||
after_create :assign_default_role | ||
|
||
private | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move all the validates in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.