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="container"> | |
| <div class="header"> | |
| Header - <a href="/products/">Product List</a> | |
| </div> | |
| <div id="product_details" style="display: none"> | |
| <% if @product.present? %> | |
| <%= render file: 'products/product' %> | |
| <% end %> | |
| </div> | |
| <ul class="products" id="product_list" style="display: none"> |
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 ProductsController < ApplicationController | |
| def index | |
| @products = Product.all | |
| if params[:product_id].present? | |
| @product = Product.find(params[:product_id]) | |
| end | |
| if params[:product_id].present? and request.xhr? | |
| render 'product', layout: false |
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, |
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
| 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
| 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
| 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
| 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
| <% 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
| <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> |