Download - RubyEnRails2007 - Dr Nic Williams - Keynote
Dr Nicdrnicwilliams.comdrnicacademy.com
What’s cool about Rails?
Remember:* setup for demo of magic_model_generator (pp 36)* set font size of database.yml to large
Dr Nic
Dr Nic’sMagic Models
MyConfPlan
CompositePrimary Keys
MagicMulti-Connections
MagicMulti-Connections
As seen on
DHH’sblog
NewGemGenerator
$ newgem <gem>
NewGemGenerator
$ newgem <gem>
As seen in
Magic ModelGenerator
Magic ModelGenerator
As seen in
??
why?
Dr Nic’s
Dr Nic’sAcademy
Dr Nic’sAcademy
“Beginning Ruby on Rails”July 7/8 - Netherlands
RailsConf
So why is important?
Why is important?
Why is important?
When do I use ?
Why is important?
Merb Camping CGI Mongrel Handlers
When do I use ?
RailsConfBetween last year and this year, I’ve realised they aren’t “Railsconfs”, but...
RailsConfBetween last year and this year, I’ve realised they aren’t “Railsconfs”, but...
RubyConfAbout web development and other things
Websites are textAnd it doesn’t matter how the text gets to the browser
<html> <head> <title>Hello world</title> </head> <body> <p>Hello World</p> </body></html>
Here’s some text that you might send
RailsWhen you come to Rails you quickly learn there are many things you need to get good at quickly...
I just want to talk about these 3...
Javascript HTML CSS
RubyRailsGems
UnixDatabasesRake
When you come to Rails you quickly learn there are many things you need to get good at quickly...
I just want to talk about these 3...
Javascript HTML CSS
RubyRailsGems
UnixDatabasesRake
When you come to Rails you quickly learn there are many things you need to get good at quickly...
I just want to talk about these 3...
RailsConf 2006To understand Rails and where its going, let’s look at rails 1.0
RailsConf 2006
“Can we make $$$ from Rails?”
To understand Rails and where its going, let’s look at rails 1.0
RailsConf 2007
RailsConf 2007
“Yes.”
RailsConf 2007
Ok, now let’s look at the latest ways to generate text on the web...
“Because its just text generation”
“Does it scale?”
Everyone worries about requests per second; but I think its more important to worry about the cost per new feature. Rails is structured to make it easy to design and implement new stuff.
“Does it scale?”
“Yes. Just add more controllers.”Everyone worries about requests per second; but I think its more important to worry about the cost per new feature. Rails is structured to make it easy to design and implement new stuff.
RESTful controllersclass PeopleController < ApplicationController # GET all or search def index... def show... def new... def edit... def create... def update... def destroy...end
RESTful controllersclass PeopleController < ApplicationController # GET all or search def index... def show... def new... def edit... def create... def update... def destroy...end
class PeopleController < ApplicationController # GET all or search def index... def show... def new... def edit... def create... def update... def destroy...end
CRUD operations
RESTful routes
/people/show/1 => /people/1
/people/some_action/45 => /people/45/some_action
Its now cool to use restful routing. The benefit is you can remove the tail of a url, and the url is still meaningful.
class PeopleController < ApplicationController
def create @person = Person.create(params[:person]) respond_to do |format| format.html { redirect_to person_url(@person) } format.xml { render :status => :created, :location => person_url(@person), ... } end endend
RESTful result typesOne of the main agreements about convention in Rails is RESTfulness.Same actions, but new paradigm.
From developer side, you can return more data formats with the same actions.
class PeopleController < ApplicationController
def create @person = Person.create(params[:person]) respond_to do |format| format.html { redirect_to person_url(@person) } format.xml { render :status => :created, :location => person_url(@person), ... } end endend
RESTful result typesOne of the main agreements about convention in Rails is RESTfulness.Same actions, but new paradigm.
From developer side, you can return more data formats with the same actions.
Any format you want
respond_to do |format| format.html { render ... } format.xml { render ... } format.csv { render ... } format.js { render ... } formal.foobar { render ... }end
ActiveResource
Applications “talking” with REST
ActiveResource
Applications “talking” with REST
This is cool because...
class Person < ActiveResource::Base self.site = "http://contacts.drnicwilliams.com:3000/"end
Person.find_by_name "Dr Nic Williams" Who cares what REST is? This syntax is awesome.
Learn more?
Read the README and CHANGELOG for ActiveResource
http://dev.rubyonrails.org/browser/trunk/activeresource/README
Jester: REST for Javascript
Base.model("Person", { plural: "people", prefix: "http://drnicwilliams.com:3000"})
Person.find("all", { premium: true }, { onSuccess: callback })
This #find call is asynchronous and invokes callback on complete.
by Eric Mill
“Logical” servers for the connector1) Jumpstart/PXE Boot
2) Monitoring
3) Auditing
4) Logging
5) Provisioning and configuration management
6) DHCP/LDAP for server identification/authentication and control (at dual for failover)
7) DNS: DNS cache and resolver, and a (private) DNS system (4x + 2; 2+ sites)
8) DNS MySQL (4x + 2, dual masters with slaves per DNS node, innodb tables)
9) SPAM filtering servers (files to NFS store and tracking to postgresql)
10) SPAM database setup (postgresql)
11) SPAM NFS store
12) SMTP proxies and gateways out
13) SMTP proxies and gateways in (delivery to clusters to Maildir over NFS)
14) Mail stores
15) IMAP proxy servers
16) IMAP servers
17) User LDAP servers
18) User long running processes
19) User postgresql DB servers
20) User web servers
21) User application servers
22) User File Storage (NFS)
23) Joyent Organization Provisioning/Customer panel servers (web, app, database)
24) iSCSI storage systems
25) Chat servers
26) Load balancer/proxies/static caches
...Jason Hoffman, Railsconf 2007
Guess which is “Rails”?
Jason Hoffman, Railsconf 2007
Jason Hoffman, Railsconf 2007
A process of ongoing improvement
Hosting
Don’t deploy Rails to Amazon’s EC2
EC2 have virtual storage - if you lose your instance, you lose data. Backup hourly.
Use EC2 for other processes on demand.
Run Ruby scripts on Amazon’s EC2
Deployment
Capistrano - by Jamis Buck
+Deprec - by Mike Bailey deprec =
deployment recipies
deprec - easy peasy
cap install_rails_stackcap setupcap deploy_with_migrationscap restart_apache
Slap ubuntu on a machine and go.
install_rails_stack
task :install_rails_stack do setup_user_perms enable_universe disable_cdrom_install install_packages_for_rails install_rubygems install_gems install_apacheend
The process of deploying rails generically is being solved
Story of 200 database tables
magic_model_generator
magicmodels.rubyforge.org
magic_model_generator
$ sudo gem install magic_model_generator$ rails magic_show$ cd magic_show # point database.yml to legacy database$ rake db:migrate # check /db/schema.rb contains all tables$ ruby script/generate magic_model # check /app/models contains model files
For demo:$ pgstart$ rails magic_show -d postgresql$ database.yml: database: activerecord_unittest$ Kill textmate and reload it fresh from magic_show folder$ Have /db and /app/models folders open and empty$ Pump up font size$ iTerm open to magic_show folder
Now, demo is ready
# Show post.rb as example
RubyGems are goodRubyGems
Instead of plugins, use gems
Dependencies
Version numbers
Use outside of Rails
Non-ruby code
“But I don’t know how?”
hoe - Ryan Davis
hoe - Ryan Davisseattle.rb - ZenTest/autotest
hoe - Ryan Davisseattle.rb - ZenTest/autotest
# Rakefilehoe = Hoe.new(GEM_NAME, VERS) do |p| p.author = AUTHOR p.description = DESCRIPTION p.email = EMAIL p.summary = SUMMARY p.url = HOMEPATHend
Its easier to write a Gem than not to!
rake
rake
History.txt== 0.2.0 2007-06-03
* Added more foo into foo.rb == 0.1.0 2007-06-02
* Foo and Bar now in own files* Using Hoe
History.txtManifest.txtREADME.txtRakefilebin/gemsonrailslib/gemsonrails.rblib/gemsonrails/version.rbscripts/txt2htmlsetup.rbtemplates/init.rbtemplates/tasks_gems_freeze.raketemplates/tasks_gems_link.raketemplates/tasks_gems_unfreeze.raketemplates/tasks_load_tasks_in_gems.raketest/test_gemsonrails.rbtest/test_helper.rbwebsite/index.htmlwebsite/index.txtwebsite/javascripts/rounded_corners_lite.inc.jswebsite/stylesheets/screen.csswebsite/template.rhtml
Manifest.txt
ordered list of published files
History.txtManifest.txtREADME.txtRakefilebin/gemsonrailslib/gemsonrails.rblib/gemsonrails/version.rbscripts/txt2htmlsetup.rbtemplates/init.rbtemplates/tasks_gems_freeze.raketemplates/tasks_gems_link.raketemplates/tasks_gems_unfreeze.raketemplates/tasks_load_tasks_in_gems.raketest/test_gemsonrails.rbtest/test_helper.rbwebsite/index.htmlwebsite/index.txtwebsite/javascripts/rounded_corners_lite.inc.jswebsite/stylesheets/screen.csswebsite/template.rhtml
Manifest.txt
ordered list of published files
rake check_manifest
NewGemGenerator
$ newgem <gemname>
newgem.rubyforge.org
Finally...
JRuby is cool
drnicacademy.com
Dr Nic Academy
Learn on !
What: Beginning RailsWhen: July 7 and 8thWhere: Amsterdam +/-BYO: LaptopCost: 975€
drnicacademy.com
What: Beginning RailsWhen: July 7 and 8thWhere: Amsterdam +/-BYO: LaptopCost: 975€
600€ - “rubyenrails”drnicacademy.com
drnicwilliams.com
by Dr Nic
Enjoy En !
drnicacademy.com