2. Me llamo Ryan Abbott
Co-founder of Loudpixel Inc.
Developing web sites/apps for nearly 10
years #angelfirecounts
Largest production Rails application is
Levee #itsawesome
Ten-ish other production apps
HI, WHO ARE YOU AGAIN?
Saturday, November 20, 2010
3. WHO/WHAT IS RUBY ON RAILS?
Web Framework built on top of Ruby
Created by David Heinemeier Hansson
DHH released Rails as open source in July
of 2004 but was the sole contributor
Rails 1.0 was released on December 13,
2005
Rails 3.0 (current) was released on
August 29, 2010 - it has 1700+
contributors
Saturday, November 20, 2010
4. WHY RAILS?
Rapid Application Development
Defaults - Scaffold, relationships,
nested objects, etc.
Plugins!
Deployment
Sites like Heroku provide free hosting,
and all you need is GIT
Community
1700+ contributors and tens of thousands
of live apps
Saturday, November 20, 2010
5. LITTLE BIG WORDS
CRUD (Create, Read, Update, Delete)
The 4 basic functions performed on the
data that our application stores
MVC (Model-View-Controller)
The architecture pattern used by rails
DRY (Don’t Repeat Yourself)
Software development principle
emphasized within the rails community
REST (Representative State Transfer)
Using identifiers to represent resources
Saturday, November 20, 2010
6. MODEL-VIEW-CONTROLLER
Models
Manages how the data is stored, and how
that data behaves
Views
Renders the models in a way best suited
for the requested format
Controllers
Receives instructions from users based
on actions, and informs the models how
they should respond and the views what
they should display
Saturday, November 20, 2010
7. REST[ful] RESOURCES
RESTful URLs provide a human readable
set of resources, and their states.
An example could be
/users/15/edit
What do we expect here?
User
Id of 15
Edit view to be displayed
Saturday, November 20, 2010
8. CREATING A RAILS PROJECT
> rails new blogpress
Creates a new directory called ‘blogpress’
containing the following:
Gemfile
Home to your GEM dependencies
app
This is where you’ll find your models,
views, and controllers
config
As you would imagine, here lives your
configurations; routes, etc.
Saturday, November 20, 2010
9. DIRECTORY BREAKDOWN CON’T
db
Contains your database schema and
migrations
log
Development, Test, and Production logs
public
Web accessible directory, images,
stylesheets, javascript, etc.
vendor
A centralized location for third-party
code from plugins to gem source
Saturday, November 20, 2010
10. APPLICATION READY, NEXT?
> bundle install
Bundler is a tool that installs required
gems for your application. Bundler is
able to determine dependencies and
children without instructions from you
database configuration (database.yml)
Defaults to sqlite, allows for MySQL,
and PostgreSQL OOB, and others with
use of plugins
development, test, production
Saturday, November 20, 2010
11. DATABASE CONFIGURED, SO...
> rake db:create
This will read the database.yml file
and create the databases requested
rake, WTF?
Rake is a way to run tasks, the
majority of tasks you run are already
provided by Rails, but you can always
create your own
> rake -T
Display a list of all rake tasks
available
Saturday, November 20, 2010
12. HELLO, WORLD? RAILS?
> rails server
Starts the rails server at port 3000 and
allows us to navigate our new site!
Check things out, in the browser view:
http://127.0.0.1:3000/
Saturday, November 20, 2010
15. DATABASE CONFIGURED, SO...
> rm public/index.html
We don’t want this page displaying
when visitors come to our blog
> rails generate controller home index
Generate a controller with only an
index action to take the place of
public/index.html
Update config/routes.rb to let the app
know that our root should be
REMOVE get "home/index"
ADD root :to => “home#index”
Saturday, November 20, 2010
18. EVERY BLOG HAS POSTS
> rails generate scaffold Post
author:string title:string content:text
permalink:text
Scaffold creates full CRUD
functionality for us, including our
model, view, controller, and even our
database migration
rake db:migrate
Calls our self.up method to create the
posts database table
Saturday, November 20, 2010
19. OH POSTS, WHERE ART THOU?
In the browser, lets have a look at:
http://127.0.0.1:3000/posts
Saturday, November 20, 2010
20. WHAT’S MISSING?
Posts
Comments (haters gone hate)
Tags / Keywords (I’m here for ONE thing)
Validation (plan for the spoon in the knife drawer)
Overall Blog
Authentication (hackers gone hack)
Most Recent Posts (laziness is contagious)
Saturday, November 20, 2010
30. AUTHENTICATION
Basic HTTP authentication prompts users
via a browser popup. This authentication
lasts until the browser is closed.
1307757
Saturday, November 20, 2010
31. MOST RECENT POSTS
1309253
We want to display the top n posts on the main page,
of course we’ll want the n more recent posts
Saturday, November 20, 2010
34. ONLINE RESOURCES?
http://tryruby.org/
A 15 minute, in-browser, tutorial showing you the
basics of Ruby
http://railsforzombies.org/
Online interactive tutorials that teach you rails
right in the browser
http://rubyonrails.org/screencasts/rails3
A set of beautiful screencasts by Gregg Pollack that
walk viewers though the details of the Rails core
pieces
http://railscasts.com/
Extremely helpful videos from Ryan Bates - started
back in 2007 Ryan is always on top of new plugins
and methods of doing things
Saturday, November 20, 2010