Tải bản đầy đủ (.pdf) (86 trang)

Rails 3 Ropes Course: Gregg Pollack ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.96 MB, 86 trang )

Rails 3 Ropes Course
Gregg Pollack
Nathaniel Bibler
Thomas Meeks
Jacob Swanner
Mark Kendall
Caike Souza
Tyler Hunt
Getting Started & Routes
Workshop - Lab #1
Bundler & ActionController
Workshop - Lab #2
ActionMailer
Workshop - Lab #3
ActiveRelation & ActiveModel
Workshop - Lab #4
XSS & UJS
Workshop - Lab #5
Rails 3 Ropes Course
!"#$%&'
Starting a New App
('$)*+
""#$%&'", ,/0"1234%25'6
734%25'+
89:5;&*
;9<=8'>&%4*?
&2)<=8&2)
4@3<==<=
.gitignore
""""""1AA;*B6""""""""""""""""C"D*4:3"4E*"$33&%F$4%25"G%4E"
"""""""""""""""""""""""""""""C"H*@I%&*"32%54%5)"42"J2:#"K$%&'"FE*FL2:4


""""""1AA*;)*6"""""""""""""""C"D*4:3"4E*"$33&%F$4%25"G%4E"
"""""""""""""""""""""""""""""C"H*@I%&*"32%54%5)"42"K$%&'"#*32'%42#J
1AA'L%3A)*@I%&*6"""""""C"M25N4"F#*$4*"$"H*@I%&*
""A#O"1AA#:9JP-,/06""""""""""C"-$4E"42"4E*"K:9J"9%5$#J"2I"J2:#"FE2%F*
""A;O"1AA;$4$9$'*PM,/,Q,DR6""C"-#*F25I%):#*"I2#"'*&*F4*;";$4$9$'*""""""""""""""""""""""""""""""
""A@O"1AA4*@3&$4*P/RS-T,/R6""C"-$4E"42"$5"$33&%F$4%25"4*@3&$4*"
A7O"1AA'L%3A$F4%B*#*F2#;6""C"DL%3",F4%B*K*F2#;"I%&*'
A/O"1AA'L%3A4*'4:5%46""""""C"DL%3"/*'4(5%4"I%&*'
AUO"1AA'L%3A3#2424J3*6"""""C"DL%3"-#2424J3*"I%&*'
AHO"1AA'L%3A)%46"""""""""""C"DL%3"H%4"%)52#*'"$5;"L**3'
!"#$%&'"4*'4.$33
""""""F#*$4*""
""""""F#*$4*""KR,MSR
""""""F#*$4*""8)%4%)52#*
""""""888
!"#$%&'
('$)*+"#$%&'"V7SS,WM"1,KHD6
/E*"@2'4"F2@@25"#$%&'"F2@@$5;'"$#*+
")*5*#$4*""""H*5*#$4*"5*G"F2;*"X'E2#4AF:4"$&%$'+"Y)YZ
F25'2&*"""""D4$#4"4E*"K$%&'"F25'2&*"X'E2#4AF:4"$&%$'+"YFYZ
'*#B*#""""""D4$#4"4E*"K$%&'"'*#B*#"X'E2#4AF:4"$&%$'+"YDYZ
;9F25'2&*"""D4$#4"$"F25'2&*"I2#"4E*";$4$9$'*"'3*F%I%*;"%5"F25I%)<;$4$9$'*8J@&
""""""""""""X'E2#4AF:4"$&%$'+"Y;9YZ
[5"$;;%4%25"42"4E2'*O"4E*#*"$#*+
"$33&%F$4%25""H*5*#$4*"4E*"K$%&'"$33&%F$4%25"F2;*
";*'4#2J""""""(5;2"F2;*")*5*#$4*;"G%4E"Y)*5*#$4*Y
"9*5FE@$#L*#""D**"E2G"I$'4"$"3%*F*"2I"F2;*"#:5'
"3#2I%&*#"""""H*4"3#2I%&*"%5I2#@$4%25"I#2@"$"3%*F*"2I"F2;*
"3&:)%5"""""""[5'4$&&"$"3&:)%5
"#:55*#"""""""K:5"$"3%*F*"2I"F2;*"%5"4E*"$33&%F$4%25"*5B%#25@*54

,&&"F2@@$5;'"F$5"9*"#:5"G%4E"AE"I2#"@2#*"%5I2#@$4%258
!"&'"'F#%34<
""
""#$%&'
!"F;"4*'4.$33<
script/generate
script/console
script/server
old scripts new hotness
script/dbconsole
rails1g
rails1c
rails1s
rails1db
script/generate
script/console
script/server
old scripts new hotness
script/dbconsole
$&%$'"#PN#$%&'N
r1g
r1c
r1s
r1db
Rails::Initializer.run do |config|
end
config/environment.rb
configuration
Rails 2
config.load_paths += %W( #{RAILS_ROOT}/extras )

config.plugins = [ :exception_notification ]
config.time_zone = 'UTC'
config.gem "bj"
config.gem "sqlite3-ruby", :lib => "sqlite3"
config.gem "aws-s3", :lib => "aws/s3"
Gemfile
config/application.rb
configuration
Rails 3
config.load_paths += %W( #{RAILS_ROOT}/extras )
config.plugins = [ :exception_notification ]
config.time_zone = 'UTC'
Gemfile
module TestApp
class Application < Rails::Application
end
end
It’s a Rack Application
New Router API
Action Dispatch
Layouts
Logger
Callbacks
Renderer
url_for
http_auth
helpers
MimeResponds
Cookies
Session

http
routing
middleware
TestApp::Application.routes.draw do |map|
end
config/routes.rb
New Routing API
Rails 3
TestApp::Application.routes.draw do |map|
end
config/routes.rb
resources :postsmap.
New Routing API
Old routing syntax works
Rails 3
map.resources :posts do |post|
post.resources :comments
end
resources :posts do
resources :comments
end
New Routing API
Rails 2
Rails 3
post.resources :comments,
:member => { :preview => :post },
:collection => { :archived => :get }
resources :comments do
member do
post :preview

end

collection do
get :archived
end
end
resources :comments do
post :preview, :on => :member
get :archived, :on => :collection
end
Rails 2
Rails 3
Rails 3
New Routing API
map.connect 'login', :controller => 'session', :action => 'new'
match 'login' => 'session#new'
Rails 2
Rails 3
map.login 'login', :controller => 'session', :action => 'new'
match 'login' => 'session#new', :as => :login
Rails 2
Rails 3
Named Route
login_path
map.root :controller => 'users', :action => 'index'
Rails 2
Rails 3
root :to => 'users#index'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

Rails 2
Rails 3
match ':controller(/:action(/:id(.:format)))'
Legacy Route
(commented out by default)
Root Paths
map.connect '/articles/:year/:month/:day', :controller => 'posts', :action => 'index'
Rails 2
Rails 3
match '/articles/:year/:month/:day' => "posts#index"
Optional Parameters
map.connect '/articles/:year/:month/:day', :controller => 'posts', :action => 'index'
map.connect '/articles/:year/:month', :controller => 'posts', :action => 'index'
map.connect '/articles/:year', :controller => 'posts', :action => 'index'
Rails 2
Rails 3
match '/articles(/:year(/:month(/:day)))' => "posts#index"
map.connect '/articles/:year', :controller => 'posts', :action => 'index',
:conditions => {:method => :get}
Rails 2
Rails 3
match '/articles/:year' => "posts#index", :via => :get
Specifying the method
Rails 3
get '/articles/:year' => "posts#index"
Rails 3
match 'signin', :to => redirect("/login")
Redirection
match 'users/:name', :to => redirect {|params| "/#{params[:name]}" }
match 'google' => redirect(' />map.connect '/:year', :controller => 'posts', :action => 'index',

:requirements => { :year => /\d{4}/ }
Rails 2
Rails 3
match '/:year' => "posts#index", :constraints => {:year => /\d{4}/}
Constraints
:constraints => { :user_agent => /iphone/ }
:constraints => { :ip => /192\.168\.1\.\d{1,3}/ }
constraints(:host => /localhost/) do
resources :posts
end
constraints IpRestrictor do
get 'admin/accounts' => "queenbee#accounts"
end
Rails 3
get 'hello' => proc { |env| [200, {}, "Hello Rack"] }
Rack Goodness
get 'rack_endpoint' => PostsController.action(:index)
get 'rack_app' => CustomRackApp
o/routing.html
For more information
Getting Started & Routes
Tutorial - Lab #1
Follow the directions in the README
Getting Started & Routes
Workshop - Lab #1
Bundler & ActionController
Workshop - Lab #2
ActionMailer
Workshop - Lab #3
ActiveRelation & ActiveModel

Workshop - Lab #4
XSS & UJS
Workshop - Lab #5
Rails 3 Ropes Course
Dependency Management

×