This file contains hidden or 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
class LineItem | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
TYPE = %w[income expense] | |
INCOME = 0 | |
EXPENSE = 1 | |
TRANSFER_IN = 'Transfer In' | |
TRANSFER_OUT = 'Transfer Out' |
This file contains hidden or 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
class PostsController < ApplicationController | |
def show | |
@post = Post.includes(comments: :user).find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @post } | |
end | |
end | |
end |
This file contains hidden or 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
<div class="post"> | |
<%= render partial: 'post', locals: {post: @post} %> | |
<hr/> | |
<div class="comments"> | |
<% @post.comments.each do |comment| %> | |
<div id="comment-<%=comment.id%>"> | |
<%= comment.user.name %> says: | |
<p> |
This file contains hidden or 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
<% cache @post do %> | |
<div class="post"> | |
<%= render partial: 'post', locals: {post: @post} %> | |
<hr/> | |
<div class="comments"> | |
<% @presenter.comments.each do |comment| %> | |
<% cache comment do %> | |
<div id="comment-<%=comment.id%>"> |
This file contains hidden or 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
class PostPresenter | |
def initialize(post) | |
@post = post | |
end | |
def comments | |
Comment.includes(:user).where(post_id: @post.id) | |
end | |
end |
This file contains hidden or 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
class PostsController < ApplicationController | |
def show | |
@post = Post.find(params[:id]) | |
@presenter = PostPresenter.new(@post) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @post } | |
end | |
end | |
end |
This file contains hidden or 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
Book: | |
{ | |
id: 1, | |
title: 'Article 1', | |
authors: [1,2] | |
} | |
Author: | |
{ | |
id: 1, |
This file contains hidden or 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
Book: | |
{ | |
id: 1, | |
title: 'Article 1', | |
authors: [{author_id: 1, name: 'Joe'}, {author_id: 2, name: 'Robert'}] | |
} |
This file contains hidden or 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
class Book | |
field :id | |
field :title | |
embeds_many :book_authors | |
# Mongoid does not offer has_many :through | |
def authors | |
book_authors.collect(&:author) | |
end |
This file contains hidden or 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
User: | |
{ | |
id: 1, | |
name: 'Joe' | |
} | |
MailBucket: | |
{ | |
user_id: 1, | |
location: 11, |
OlderNewer