Skip to content

Instantly share code, notes, and snippets.

View awongh's full-sized avatar
🍕
Snacking on pizza. Coding.

Akira Wong awongh

🍕
Snacking on pizza. Coding.
View GitHub Profile
class CandyJar < ActiveRecord::Base
has_many :candies
accepts_nested_attributes_for :candies, :reject_if => lambda { |a| a[:pricing_type_id].blank? }, :allow_destroy => true
#custom validators for nested attributes arrays
validate :has_candy #returns true if at least one candy attribute is passed
...
FactoryGirl.define do
factory :candy do
candy_jar #name the association
user_id 1
description { Faker::Lorem.paragraph 4 }
rating 1
end
end
FactoryGirl.define do
factory :candy_jar do
user_id 1
description { Faker::Lorem.paragraph 4 }
rating 0
before(:create) { |candy_jar|
candy_jar.candies.build( [FactoryGirl.attributes_for( :candies )] )
}
end
FactoryGirl.create(:candy_jar)
### Screen Casts:
- part 1: intro to events: https://youtu.be/1rKKtzKE01g
- part 2: using events in tic tac toe:https://www.youtube.com/watch?v=dYaHRkC3IbY
### Notes:
https://github.com/ga-students/WDI_skywalker/blob/master/w02/d02/INSTRUCTOR/events.md
### Questions: (please write out your answers)
- what is an event?
- why does an event happen?
html {
font-family: sans-serif;
}
body {
margin: 0;
}
h1{
margin-top:30px;
text-align:center;
}
<html>
<head>
<link href="styles.css" rel="stylesheet">
</head>
<body>
<h1>tic tac toe</h1>
<div id="board">
<div><button id="a1" class="cell">x</button><button id="a2" class="cell">o</button><button id="a3" class="cell">x</button></div>
<div><button id="b1" class="cell">x</button><button id="b2" class="cell">x</button><button id="b3" class="cell">o</button></div>
<div><button id="c1" class="cell">x</button><button id="c2" class="cell">o</button><button id="c3" class="cell">o</button></div>
@awongh
awongh / gist:50a150ecedaccf177544
Last active August 29, 2015 14:23
jquery translation exercises
//If these DOM elements don't exist yet, just create them!!!!!
// 1
var h3 = document.querySelector('h3');
// 2
var h3 = document.querySelector('h3');
h3.innerText = "Monkey Cheese";
// 3
@awongh
awongh / sinatra
Last active October 21, 2015 16:31
# Welcome
---
## Sinatra
---
### After this you will be able to:
- make an instance of a web server and have it serve content to a user
## User Auth Rails app: What we're adding:
- User model
```bash
rails g model user username:string password_hash:string
```
- user_id foreign key in tables (user has many cars)
generate a migration
```bash
rails generate migration addUserId