named path | http verb | crud operation | controller action | action has a view? | view shows 1 or many? | pertains to one persisted record? | url | adtl data needed | rails route |
---|---|---|---|---|---|---|---|---|---|
books_path | get | reading | index |
yes | many | no | /books | -- | get 'books/' => 'books#index', :as => :books |
new_book_path | get | reading* (creating) | new |
yes | one* | no | /books/new | -- | get 'books/new' => 'books#new', :as => :new_book |
post | creating | create |
no | -- | no | /books | { } | post 'books/' => 'books#create' |
|
book_path(:id) | get | reading | show |
yes | one | yes | /books/:id | -- | get 'books/:id' => 'books#show', :as => :book |
edit_book_path(:id) | get | reading* (updating) | edit |
yes | one | yes | /books/:id/edit | -- | get 'books/:id/edit' => 'books#edit', :as => :edit_book |
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
1. Time to show what you know about making Rails apps without scaffold. Keep the beers (you'll use them for the relationships lesson), but now we're headed for the bookstore. | |
2. Single model app for now. You need to decide the types that are most appropriate, and generate the model. Go ahead and make a matching controller. | |
Each book entry should have: | |
- A title | |
- An author | |
- A publication year | |
- An ISBN | |
- A genre |
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
// Welcome! We're going to go from nothingness to JS generators in 200 lines. | |
// But first, some vocab: | |
// Let's use the word chore instead of function and | |
// let's think of a chore as a "to-do" list of instruction(s) | |
// We'll use the "function" syntax to define a chore's to-do instruction(s), | |
// including input(s) and expected ouput, if any | |
// Note, "return" basically says, "quit doing stuff (even if you have more to do) and output something" | |
// Lastly, var is a way to give bits of code a name |
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
import csv | |
import collections | |
from operator import attrgetter | |
from myApp.models import User | |
csvfile = open("users.csv", "wb") | |
objects = User.objects.all() | |
fields = collections.OrderedDict([("First name", "first_name"),("Last name", "last_name"),("Email", "email"),]) | |
writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL) |
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
#!/bin/sh | |
# Script to generate a baseline of known good values for a FreeBSD 10.x server | |
# The outputs should be able to be diff'd later to verify that no changes have occured | |
BASELINE=baseline | |
SUDO=/usr/local/bin/sudo | |
/bin/rm -rf $BASELINE | |
/bin/mkdir $BASELINE | |
/bin/hostname > $BASELINE/hostname |
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 create | |
test = Test.new format_params(params) | |
test.normalize_data | |
if test.save | |
render json: test | |
else | |
puts test.errors.messages | |
render text: test.errors.messages | |
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
import org.json.JSONArray; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import java.util.*; | |
public class JsonHelper { | |
public static Object toJSON(Object object) throws JSONException { | |
if (object instanceof Map) { | |
JSONObject json = new JSONObject(); |
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 Bicycle | |
attr_reader :size, :chain, :tire_size | |
def initialize(args={}) | |
@size = args[:size] | |
@chain = args[:chain] || default_chain | |
@tire_size = args[:tire_size] || default_tire_size | |
post_initialize(args) | |
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
class Bicycle | |
attr_reader :size, :parts | |
def initialize(args={}) | |
@size = args[:size] | |
@parts = args[:parts] | |
end | |
def spares | |
parts.spares |
There are three great virtues of a programmer:
- Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it.
- Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to.
- Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.
Four rules for developers:
OlderNewer