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
def find_or_fabricate model, attrs = {} | |
model_klass = model.to_s.camelize.constantize | |
if model_klass.where(attrs).count == 0 || die_roll(model_klass.where(attrs).count % 5) | |
Fabricate model, attrs | |
else | |
model_klass.where(attrs).offset(rand(model_klass.where(attrs).count)).first | |
end | |
end | |
def die_roll faces = 6 |
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
<link rel="import" href="../bower_components/polymer/polymer.html"> | |
<link rel="import" href="../bower_components/paper-button/paper-button.html"> | |
<link rel="import" href="shared-styles.html"> | |
<dom-module id="matched-bank"> | |
<template> | |
<style include="shared-styles"> | |
</style> | |
<div class="matchedBank"> | |
<span>[[displayedBank.name]]</span> |
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
<link rel="import" href="../bower_components/polymer/polymer.html"> | |
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html"> | |
<dom-module id="bankdata-ajax"> | |
<template> | |
<iron-ajax | |
id="request_courier" | |
url="[[url]]" | |
handle-as="json" | |
last-response="{{resultingData}}"> | |
</iron-ajax> |
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
class ApplicationController | |
#logs of code omitted | |
before_filter :define_file_locator | |
def define_file_locator | |
self.class.send :define_method, :log_file_location, lambda { | |
instance_eval 'Rails.logger.info "File location: #{__FILE__}"' | |
} | |
log_file_location |
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
artists = all artists | |
for each artist | |
grab all tracks by artist | |
grab all genres for tracks | |
count number of unique genres | |
note the number of genres for the artist | |
start with the first artist | |
compare her number of genres with the number of genres for the second artist | |
whoever has more is the leader |
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
Commenting on notes: | |
- generate comments scaffold (controller, model, migration, views) | |
- add comment link and comment form spot to comment partial | |
- tell CommentsController#new to respond to JS requests | |
- create new.js.erb partial for comments controller |
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
class UsersHaveAvatar < ActiveRecord::Migration | |
def up | |
add_column :users, :avatar, :string | |
end | |
def down | |
remove_column :users, :avatar | |
end | |
end |
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
A Rails app has a few top-level folders that serve different purposes. This might vary from app to app, but most apps use this basic structure pretty faithfully. | |
app | |
This folder is where most of your code goes. It has folders for your controllers (navigation logic), models (business logic), and views (display templates). Sometimes developers create extra folders in here for objects like mailers and observers. In Rails 3.1, an assets folder joined this group. The assets folder contains files that get compiled into javascript code, stylesheets, and images. These asset files are written in Ruby-like languages, but the rest of the code in the app folder is Ruby. | |
config | |
This folder has files that run when your app starts, including environment.rb and database.yml. They control decisions about how the app works in different scenarios (examples: which email account should be used for outgoing messages? which database should be used for data stored by this server?). The config folder also contains credent |
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
These are the steps you will probably need to take, to get a new Rails app running. | |
1. install Rails | |
2. create a new Rails app | |
3. navigate into the root directory of your app | |
4. generate a scaffold |
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
First, download GitHub for Mac (or install git). | |
http://mac.github.com | |
Then, go to the community_pics repository page and click "Clone in Mac" | |
http://github.com/schwabsauce/community_pics | |
Open a Terminal window and move into the community_pics directory | |
$ cd Documents/community_pics | |
Then run bundle and rake db:migrate. |
NewerOlder