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 User < ApplicationRecord | |
| has_many :comments, dependent: :destroy | |
| 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.includes(:comments).find(params[: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
| Post Load (0.4ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT $1 [["LIMIT", 1]] | |
| Comment Load (0.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_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
| Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 [["id", 1]] | |
| Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 1]] | |
| Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 2]] | |
| Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 3]] | |
| Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 4]] | |
| .... |
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
| ... | |
| <ul> | |
| <% @post.comments.each do |comment| %> | |
| <li><%= comment.content %></li> | |
| ... |
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]) | |
| 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
| Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 [["id", 1]] | |
| Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 1]] | |
| Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 2]] | |
| Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 3]] | |
| Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 4]] |
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
| app/controllers/posts_controller.rb | |
| class PostsController < ApplicationController | |
| def show | |
| @post = Post.find(params[:id]) | |
| end | |
| end | |
| ``` | |
| ```ruby | |
| app/views/posts/index.html.erb |
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
| import React from 'react'; | |
| import { imagePath } from 'rwr-view-helpers'; | |
| import { facebookIcon } from 'constants/icon-urls'; | |
| export default ({ alt }) => ( | |
| <img alt={alt} src={imagePath(facebookIcon)} /> | |
| ); |
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
| go | |
| func (a Vector) Normalize() Vector { | |
| return a.MultiplyByScalar(1. / a.Length()) | |
| } | |
| func TestNormalize(t *testing.T) { | |
| assert.Equal(t, Vector{1., 0., 0.}, Vector{10., 0., 0.}.Normalize(), | |
| "returns a unit vector (versor) from the given vector") | |
| assert.Equal(t, Vector{0., 1., 0.}, Vector{0., 10., 0.}.Normalize(), | |
| "returns a unit vector (versor) from the given vector") |