class Product < ApplicationRecord
end
 
 
Model.update_all "deleted = 1"
 
"The annotate_models gem automatically adds and updates comments at the top of
each model summarizing the schema if you desire that functionality."
 
 
 
obj.update_all
obj.update_attribute
obj.update_column
obj.update_columns
 
obj.update(attributes)
Model.update(id, attributes)
 
 
obj.errors[:attribute]
 
irb> Person.new.errors[:name].any?  false
irb> Person.create.errors[:name].any?  true
 
irb> p.valid?
irb> p.errros[:name].any?  true
 
irb> p.validate 
irb> p.errros[:name].any?  true
 
 
class Person < ApplicationRecord
  validates :name, presence: true
end
 
>> person = Person.new
>> person.valid?
>> person.errors.details[:name]  [{error: :blank}]
 
validates :terms_of_service, acceptance: true 
 
class Person < ApplicationRecord
  validates :email, confirmation: true
  validates :email_confirmation, presence: true
end
 
 
validates :username, uniqueness: { case_sensitive: true } 
validates :email, uniqueness: { case_sensitive: false }
 
 
validates :username, message: ->(object, data) do
  "Sorry  
end
 
validates username, uniqueness: true, on: create 
validates username, uniqueness: true, on: update 
 
 
errors.add(:username, 'blah')
errors.messages[:name] << 'blah'
 
 
errors.add(:name, :invalid_characters)
errors.add(:name, "cannot contain the characters !@)
 
 
 
def my_custom_validator
  errors.add(:username, 
end
 
create_table :accounts do |t|
  t.belongs_to :supplier, index: true, unique: true, foreign_key: true
  
end
 
 
@author = @book.reload.author
 
client = Client.take 
clients = Client.take(2)
 
User.find_each do |user|
  
end
 
User.where(weekly_subscriber: true).find_each do |user|
  
end
 
Person.find_each.with_index do |person, index|
  
end
 
Person.where("age > 21").find_in_batches do |group|
end
 
 
if something_true
  return Articles.where(something:x)
else
  return Articles.none
end
 
 
class Article < ApplicationRecord
  scope :published, -> { where(published: true) }
end
 
class Article < ApplicationRecord
  def self.published
    where(published: true)
  end
end
 
 
 
class Client < ApplicationRecord
  default_scope { where("removed_at IS NULL") }
end
 
 
class Client < ApplicationRecord
  def self.default_scope
    
  end
end
 
 
 
Client.unscoped.all
 
Client.unscoped {
  Client.created_before(Time.zone.now)
}
 
 
 
class Book < ApplicationRecord
  enum availability: [:available, :unavailable]
end
 
Book.where(availability: :available)
Book.available
 
 
Client.exists?(1)
Client.exists?(id: [1,2,3]) 
 
 
 
<body>
  <%= yield :links %>
  <%= yield %>
</body>
 
<% content_for :links do %>
  <a href='/home'>Home</a>
<% end %>
 
 
 
<% if local_assigns[:full] %>
<%= simple_format article.body %>
<% else %>
<%= truncate article.body %>
<% end %>
 
<% if defined? full %>
<%= simple_format article.body %>
<% else %>
<%= truncate article.body %>
<% end %>
 
<:% render object:@user, locals:{var1:1} %> 
<:% render partial: object:@user, locals:{var1:1} %> 
 
<% render @customer %>
 
<%= render partial: 'shared/one', collection:[1,2,3] %>