Skip to content

Instantly share code, notes, and snippets.

@PerezIgnacio
Last active February 3, 2020 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PerezIgnacio/e1babd9cab20f79131941c142b89b402 to your computer and use it in GitHub Desktop.
Save PerezIgnacio/e1babd9cab20f79131941c142b89b402 to your computer and use it in GitHub Desktop.
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