Skip to content

Instantly share code, notes, and snippets.

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 xenodesystems/3904734 to your computer and use it in GitHub Desktop.
Save xenodesystems/3904734 to your computer and use it in GitHub Desktop.
Xenode Rails Samples #3
# [Mongoid] "ActiveRecord like" CRUD (Create-Read-Update-Destroy)
# CREAR POSTS:
Post.create(title: "Nuestro Primer Post", content: "Contenido para el primer post")
# LEER/ENCONTRAR POSTS:
Post.all.to_a # (todos)
Post.all[id] # (uno)
# Después de encontrar 1 post:
Post.title # (Nos regresa el título de ese post)
Post.content # (Nos regresa el contenido de ese post)
# ACTUALIZAR POSTS:
post.update_attribute(content: "Contenido Cambiado")
# (cambia 1 atributo) [con/de la variable "post" definida con los métodos de LEER]
post.update_attributes(title: "Primer Post", content: "El contenido")
# (para cambiar todos los atributos) [con/de la variable "post" definida con los métodos de LEER]
# DESTRUIR POSTS:
Post.all[id].destroy # [con variable "post" que nosotros elijamos según id]
Post.destroy_all # (Destruir todos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment