Last active
February 3, 2020 18:39
-
-
Save PerezIgnacio/e1babd9cab20f79131941c142b89b402 to your computer and use it in GitHub Desktop.
User with nested attributes and validations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
RECENT_ORDER_DAYS = 3 | |
RECENT_VISITED_DAYS = 7 | |
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable | |
has_many :orders | |
has_one :user_request | |
accepts_nested_attributes_for :user_request, allow_destroy: true | |
validates :name, presence: true | |
validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i } | |
validates :phone, uniqueness: true, allow_blank: true | |
validates :password, presence: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment