Presentação-Herminio-CearaOnRails-08-04-09
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Presentação-Herminio-CearaOnRails-08-04-09

  • 1,438 views
Uploaded on

Apresentação sobre rotas no rails na primeira edição do Ceara On Rails de 2009 que ocorreu na data de 08//04/2009

Apresentação sobre rotas no rails na primeira edição do Ceara On Rails de 2009 que ocorreu na data de 08//04/2009

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,438
On Slideshare
1,284
From Embeds
154
Number of Embeds
4

Actions

Shares
Downloads
10
Comments
0
Likes
0

Embeds 154

http://www.herminiotorres.com 80
http://www.cearaonrails.org 56
http://trendti.me 15
http://www.linkedin.com 3

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. URL não mapeada?
  • 2. RESTful
  • 3. REST?
  • 4. Verbos HTTP Ações CRUD
  • 5. Verbos HTTP Ações CRUD
  • 6. Verbos HTTP Ações CRUD
  • 7. Verbos HTTP Ações CRUD
  • 8. Rails on REST
  • 9. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos end
  • 10. URLs e Caminhos
  • 11. URLs e Caminhos Action_controller_url http://www.exemplo.com.br/photos
  • 12. URLs e Caminhos Action_controller_path http://www.exemplo.com.b /photos
  • 13. Customizando Recursos
  • 14. :controller
  • 15. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :controller => “images” end
  • 16. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :controller => “images” end
  • 17. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :controller => “images” end /photos
  • 18. :as
  • 19. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :as => “images” end
  • 20. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :as => “images” end
  • 21. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :as => “images” end /photos
  • 22. :as :controller /photos /photos
  • 23. :as :controller /photos /photos
  • 24. :as :controller /photos /photos
  • 25. :path_names
  • 26. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :path_names => { :new => ‘novo’, :edit => ‘editar’ } end
  • 27. # config/enviroment.rb Rails::Initializer.run do |config| config.action_controller.resources_path_names { :new => ‘novo’, :edit => ‘editar’ } end
  • 28. p://www.example.com.br Raiz do Site ou root(não muda)‫‏‬
  • 29. / photos / novo p://www.example.com.br controller action Raiz do Site ou root(não muda)‫‏‬
  • 30. id p://www.example.com.br / photos / 1 / editar Raiz do Site ou root(não muda)‫‏‬ controller action
  • 31. aninhada
  • 32. model class Magazine < ActiveRecord::Base # has_many é um relacionamento has_many :ads end class Ad < ActiveRecord::Base # belongs_to é um relacionamento belongs_to :magazine end
  • 33. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :magazines do |magazine| magazine.resources :ads end end
  • 34. model + routes
  • 35. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :magazines, :has_many => :ads end
  • 36. a url ficaria como?
  • 37. Assim? id //www.example.com.br / photos?id=1&editar controller action Raiz do Site ou root(não muda)‫‏‬
  • 38. id //www.example.com.br / photos / 1 / editar controller action Raiz do Site ou root(não muda)‫‏‬
  • 39. id E quais as vantagens? / photos / 1 / editar controller action
  • 40. E uma rota aninhada com várias outras?
  • 41. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos do |photo| photo.resource :photographer photo.resources :publications photo.resources :versions end end
  • 42. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos do |photo| photo.resource :photographer photo.resources :publications photo.resources :versions end end Lindo! Não?
  • 43. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos do |photo| photo.resource :photographer photo.resources :publications photo.resources :versions end end Não
  • 44. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :photos, :has_one => :photographer, :has_many => [ :publications, :versions ] end Lindo!
  • 45. Uma rota aninhada dentro de outra rota aninhada?
  • 46. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :publishers do |publisher| publisher.resources :magazines do |magazine| magazine.resources :photos end end end
  • 47. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :publishers do |publisher| publisher.resources :magazines do |magazine| magazine.resources :photos end end end _path: /publishers/1/magazines/2/photos/3
  • 48. :shallow
  • 49. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resources :publishers, :shallow => true do |publisher| publisher.resources :magazines do |magazine| magazine.resources :photos end end end _path: /publishers/1 _path: /publishers/1/magazines _path: /magazines/2 _path: /magazines/2/photos _path: /photos/3
  • 50. regular
  • 51. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.connect ‘:controller/:action/:id’ map.connect ‘:controller/:action/:id.:format’ end
  • 52. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.connect ‘:controller/:action/:id’ map.connect ‘:controller/:action/:id.:format’ end
  • 53. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.connect ‘:controller/texto_estatico/:id’ end
  • 54. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.connect ‘photo/:id’, :controller => ‘photos’, :action => ‘show’ end
  • 55. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.connect ‘photo/:id’, :controller => ‘photos’, :action => ‘show’, :defaults => { :format => ‘jpg’ } end
  • 56. nomeada
  • 57. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.logout ‘/logout’, :controller => ‘sessions’, :action => ‘destroy’ end
  • 58. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.login ‘/login’, :controller => ‘sessions’, :action => ‘new’, :conditions => { :method => :post } end
  • 59. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.with_options :controller => ‘photos’ do |photo| photo.delete ‘:id/delete’, :action => ‘delete’ photo.edit ‘:id/edit’, :action => ‘edit’ end end
  • 60. padrão
  • 61. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.root :controller => ‘pages’, :action => ‘main’ end
  • 62. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.root :controller => ‘pages’, :action => ‘main’ end
  • 63. # config/routes.rb ActionController::Routing::Routes.draw do |map| map.index ‘index’, :controller => ‘pages’, :action => ‘main’ map.root :index end
  • 64. end
  • 65. obrigado!