Diferencia entre revisiones de «Rails»

De Furilo
Ir a la navegación Ir a la búsqueda
(Página creada con «Rails snippets and whatnot... # Update all customers with the given attributes Customer.update_all wants_email: true # Update all books with 'Rails' in their title B...»)
 
 
(No se muestran 3 ediciones intermedias del mismo usuario)
Línea 1: Línea 1:
 
Rails snippets and whatnot...
 
Rails snippets and whatnot...
 +
 +
# simple attribute update
 +
u.update_attribute :roles_mask, 3
  
 
  # Update all customers with the given attributes
 
  # Update all customers with the given attributes
Línea 9: Línea 12:
 
  # Update all books that match conditions, but limit it to 5 ordered by date  
 
  # Update all books that match conditions, but limit it to 5 ordered by date  
 
  Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(author: 'David')
 
  Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(author: 'David')
 +
 +
# save records (to force validations)
 +
Issue.all.each { |n| n.save }
 +
 
 +
Reason.find_each { |reason| reason.create_activity :create, owner: reason.user }
 +
Issue.find_each { |i| i.create_activity :create, owner: i.user }

Revisión actual del 09:18 31 dic 2015

Rails snippets and whatnot...

# simple attribute update
u.update_attribute :roles_mask, 3 
# Update all customers with the given attributes
Customer.update_all wants_email: true

# Update all books with 'Rails' in their title
Book.where('title LIKE ?', '%Rails%').update_all(author: 'David')

# Update all books that match conditions, but limit it to 5 ordered by date 
Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(author: 'David')
# save records (to force validations)
Issue.all.each { |n| n.save }
 
Reason.find_each { |reason| reason.create_activity :create, owner: reason.user }
Issue.find_each { |i| i.create_activity :create, owner: i.user }