-
Corey Speisman
-
I'm a developer at The Sunlight Foundation.
- I maintain the Capitol Words API, and Simple Socialite gulp package
- Work on OpenCongress.org redesign
- and contribute to a bunch of opensource projects dealing with Government transparency
-
You can email me anytime: [email protected].
-
I'm @cdspeis just about everywhere.
- What is programming? (briefly)
- Intro to ruby
- Intro to object-oriented programming
- Intro to rails
When you tell someone to make a sandwich, your job is made much easier because they already know what a sandwich is.
If you were to tell your computer to make a sandwich you would have to give very specific directions.
- open cabinet
- see if there is bread
- if there is no bread go to the store and buy bread
- open bread packaging and take out 2 slices
--
Programming is telling your computer how to do something. Large tasks must be broken up into smaller tasks, which must be broken up into even smaller tasks, down until you get to the most basic tasks that you don't have to descibe - and that your computer already knows how to do.
In order to tell your computer how to do something, you must use a programming language.
--
... that's where ruby comes into play!
Ruby is a object oriented pogramming language that is simple, easy to learn, and elegant.
5.times do
puts "Hi, there!"
end
--
It is a framework built with ruby and uses ruby to build websites
- Handles web requests
- Easily configures to any database
- makes best practice assumptions so that we don't have to
We are going to be using nitrous.io
Here are the code examples: Code along
--
puts "what is your name?"
name = gets.chomp
puts "Hi #{name}, how are you??"
- variables
- methods
- arrays
- hashes
methods are a lot like variables
you save values to variable names
you save certain instructions to method names
Arrays & Hashes
Instructions: Prompts user to enter a word
- Tells user to enter another word or hit the return key
- Repeats that process until the user hits the return key
- Returns all the words entered in alphabetical order
- Objects are basic building blocks of Ruby
- Literally everything is an object in Ruby
- You can think of Objects as any noun (users, computers , animals, cars, pets, houses, etc..etc)
There are two steps to creating an object in ruby
Classes are basically your blueprint or a template for your object
class Person
def initialize(name)
puts "A user is being created"
end
end
A class can be used to create many objects
The second step is to instantiate the object (aka create your object from the class)
person1 = Person.new('Corey')
person2 = Person.new('Pat')
class ClassName
end
class definition starts with the keyword class followed by the class name and is delimited with end
class Box
def initialize(w,h)
@width = w
@height = h
end
end
The initialize method is considered our constructor. It is used when you want to initialize class variables at the same time as creating your class
@width = w
@height = h
instance variables are class attributes and become properties of the object when an object is instanciated. They can also be passed between all of the class methods
#accessor methods
# define a class
class Box
# constructor method
def initialize(w,h)
@width, @height = w, h
end
# accessor methods
def printWidth
@width
end
def printHeight
@height
end
end
# create an object
box = Box.new(10, 20)
# use accessor methods
x = box.printWidth
y = box.printHeight
accessor methods allow us to access our instance variables from outside of the class
--
- Open Source Framework
- Built with and uses the ruby programming language
- Uses MVC framework (model, view. controller)
Let's talk a little bit about databases
Let's just jump into and build something cool!
rails new [name of app]
creates a new rails apprails generate scaffold [model name] [fields:datatype]
generates the rails scaffoldrake db:migrate
migrates over the database schema from ruby land to sql landrails s
starts the rails server