# Objects
Specific "Things" in ruby
# Objects
* Me
* a blog post
* your comment on a blog
* Minecraft
* a purple pen
* a tweet
* the Eagles
# Classes
Types of "things"
# Classes
* Person
* Post
* Comment
* Player
* Game
* Pen
* Message
* Team
# Classes?
* Me
* a blog post
* your comment on a blog post
* Minecraft
* a purple pen
* a tweet
* the Eagles
# I'm making:
## a Message Board App
# What classes should I have?
# My classes
* Post
* User
# Attributes
Data that makes an object specific
# What attributes would Post have?
# Post
* name
* description
* image
* (id, created\_at, updated\_at)
# Types
Tells Ruby what kind of data an attribute holds
* string
* integer
* decimal
* datetime
# Post Attribute Types?
* name
* description
* image
* (id, created\_at, updated\_at)
# Model =
Class + Attributes + Types ( + methods)
# Make models with
rails generate model ...
rails generate model post \
name:string \
description:string \
image:string
Look in app/models/post.rb
That's your model
class Post < ActiveRecord::Base
attr_accessible :description, :image, :name
end
So destroy the model
rails destroy model post
And make a scaffold
rails generate scaffold post \
name:string \
description:string \
image:string
# Scaffold =
Model + Views + Controllers
run this
rake db:migrate
* start your sever
* go to [http://localhost:3000/posts](http://localhost:3000/posts)
Try one of these:
* [http://localhost:3000](http://localhost:3000)
* [http://127.0.0.1:3000](http://127.0.0.1:3000)
# Try putting in some data
# How about a real image?
app/views/posts/show.html.erb
before
after
or
# Views
<p>Mix html <%= with_ruby_code %></p>
# Try some things
Come from the controller
app/controllers/posts_controller.rb
# Try it out, see what breaks!
# Homework
Make a scaffold for your app, make some changes to the view files.