Created
October 17, 2012 09:50
-
-
Save xenodesystems/3904734 to your computer and use it in GitHub Desktop.
Xenode Rails Samples #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [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