Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
User with nested attributes and validations
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
You can’t perform that action at this time.