Your SlideShare is downloading. ×
0
RoutingHamamatsurb#4 2011.06.08 @mackato
Wiki or CMS    5
Routing
Version 1.9.2             Version 3.0.7.rvmrcrvm ruby-1.9.2-p180@rails-3_0_7
rails new rails3dojo -m http://railswizard.org/ae25c16f22597ad5ea98.rb -J -T
≠ CSS   ≠ Erb
Gemfilegem rake, 0.8.7    gem uninstall rake -v=0.9.x    bundle update          ※ Rails3.1   0.9.1   OK!
Mac only!cd ~/.powln -s /path/to/rails3dojoopen http://rails3dojo.dev/
http://localhost:3000/rm public/index.html public/images/rails.png
http://localhost:3000/     Routing
HTTP         Methods: GET, POST, PUT, DELETE         Paths:   /login, /pages/2, /items.xml                           param...
rails g controller welcome index
spec/controllers/welcome_controller_spec.rb    # -*- coding: utf-8 -*-    require spec_helper    describe WelcomeControlle...
bundle exec rspec spec/controllers/welcome_controller_spec.rb
config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to =...
spec/controllers/welcome_controller_spec.rb    # -*- coding: utf-8 -*-    require spec_helper    describe WelcomeControlle...
http://localhost:3000/
www.getskeleton.com/
http://html2haml.heroku.com/
rm -f app/views/layouts/application.html.erbgit clone git://gist.github.com/1012788.gitmv 1012788/application.html.haml ap...
http://localhost:3000/
config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to =...
% rake routes     root          /(.:format)               {:controller=>"welcome", :action=>"index"}    pages GET      /pa...
Collection                    Member            Pages                         Pageindex    GET pages_path      show      G...
rails g controller pages index new
http://localhost:3000/pages
http://localhost:3000/pages/new
spec/controllers/pages_controller_spec.rb# -*- coding: utf-8 -*-require spec_helperdescribe PagesController do  describe "...
app/views/layouts/application.html.haml<!doctype html>...        %h3 Shortcuts        %ul          %li= link_to "Home", ro...
http://localhost:3000/
config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to =...
% rake routes...    admin_pages GET      /admin/pages(.:format)            {:action=>"index", :controller=>"admin/pages"} ...
config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to =...
rake routes...    page_comments GET      /pages/:page_id/comments(.:format)            {:action=>"index", :controller=>"co...
config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to =...
rake routes(in /Users/kato/sandbox/rails3dojo)        root        /(.:format)                    {:controller=>"welcome", ...
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編
Upcoming SlideShare
Loading in...5
×

浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編

2,469

Published on

2011/6/8 Hamamatsu.rb#4の浜松Rails3道場の資料です。

https://github.com/hamamatsu-rb/rails3dojo

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,469
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
25
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "浜松Rails3道場 其の壱 プロジェクト作成〜Rouging編"

  1. 1. RoutingHamamatsurb#4 2011.06.08 @mackato
  2. 2. Wiki or CMS 5
  3. 3. Routing
  4. 4. Version 1.9.2 Version 3.0.7.rvmrcrvm ruby-1.9.2-p180@rails-3_0_7
  5. 5. rails new rails3dojo -m http://railswizard.org/ae25c16f22597ad5ea98.rb -J -T
  6. 6. ≠ CSS ≠ Erb
  7. 7. Gemfilegem rake, 0.8.7 gem uninstall rake -v=0.9.x bundle update ※ Rails3.1 0.9.1 OK!
  8. 8. Mac only!cd ~/.powln -s /path/to/rails3dojoopen http://rails3dojo.dev/
  9. 9. http://localhost:3000/rm public/index.html public/images/rails.png
  10. 10. http://localhost:3000/ Routing
  11. 11. HTTP Methods: GET, POST, PUT, DELETE Paths: /login, /pages/2, /items.xml params[:id] format : Rails Routing from the Outside In. http://guides.rubyonrails.org/routing.html
  12. 12. rails g controller welcome index
  13. 13. spec/controllers/welcome_controller_spec.rb # -*- coding: utf-8 -*- require spec_helper describe WelcomeController do   describe "#index" do     it "should be successful" do       get index       response.should be_success     end          it "GET / " do       { :get => "/" }.should route_to(         :controller => "welcome",         :action => "index" )     end   end end
  14. 14. bundle exec rspec spec/controllers/welcome_controller_spec.rb
  15. 15. config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to => "welcome#index"end WelcomeController#index root_path => / root_url => http://localhost:3000/
  16. 16. spec/controllers/welcome_controller_spec.rb # -*- coding: utf-8 -*- require spec_helper describe WelcomeController do   describe "#index" do     it "should be successful" do       get index       response.should be_success     end          it "GET root_path " do       { :get => root_path }.should route_to(         :controller => "welcome",         :action => "index" )     end   end end
  17. 17. http://localhost:3000/
  18. 18. www.getskeleton.com/
  19. 19. http://html2haml.heroku.com/
  20. 20. rm -f app/views/layouts/application.html.erbgit clone git://gist.github.com/1012788.gitmv 1012788/application.html.haml app/views/layouts/rm -rf 1012788git clone git://gist.github.com/1012756.gitrm -rf 1012756/.gitmv 1012756 public/stylesheets/sass
  21. 21. http://localhost:3000/
  22. 22. config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to => "welcome#index"    resources :pagesend
  23. 23. % rake routes root /(.:format) {:controller=>"welcome", :action=>"index"} pages GET /pages(.:format) {:action=>"index", :controller=>"pages"} POST /pages(.:format) {:action=>"create", :controller=>"pages"} new_page GET /pages/new(.:format) {:action=>"new", :controller=>"pages"}edit_page GET /pages/:id/edit(.:format) {:action=>"edit", :controller=>"pages"} page GET /pages/:id(.:format) {:action=>"show", :controller=>"pages"} PUT /pages/:id(.:format) {:action=>"update", :controller=>"pages"} DELETE /pages/:id(.:format) {:action=>"destroy", :controller=>"pages"}
  24. 24. Collection Member Pages Pageindex GET pages_path show GET page_path(id)new GET new_page_path edit GET edit_page_path(id)create POST pages_path update PUT page_path(id) destroy DELETE page_path(id)
  25. 25. rails g controller pages index new
  26. 26. http://localhost:3000/pages
  27. 27. http://localhost:3000/pages/new
  28. 28. spec/controllers/pages_controller_spec.rb# -*- coding: utf-8 -*-require spec_helperdescribe PagesController do  describe "#index" do    ...    it "GET pages_path " do      { :get => pages_path }.should route_to(:controller => "pages", :action => "index" )    end  end  describe "#new" do    ...    it "GET new_page_path " do      { :get => new_page_path }.should route_to(:controller => "pages", :action => "new" )    end  endend
  29. 29. app/views/layouts/application.html.haml<!doctype html>...        %h3 Shortcuts        %ul          %li= link_to "Home", root_path          %li= link_to "Pages", pages_path          %li= link_to "New Page", new_page_path
  30. 30. http://localhost:3000/
  31. 31. config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to => "welcome#index"    resources :pages    namespace "admin" do    resources :pages  endend http://localhost:3000/admin/pages
  32. 32. % rake routes... admin_pages GET /admin/pages(.:format) {:action=>"index", :controller=>"admin/pages"} POST /admin/pages(.:format) {:action=>"create", :controller=>"admin/pages"} new_admin_page GET /admin/pages/new(.:format) {:action=>"new", :controller=>"admin/pages"}edit_admin_page GET /admin/pages/:id/edit(.:format) {:action=>"edit", :controller=>"admin/pages"} admin_page GET /admin/pages/:id(.:format) {:action=>"show", :controller=>"admin/pages"} PUT /admin/pages/:id(.:format) {:action=>"update", :controller=>"admin/pages"} DELETE /admin/pages/:id(.:format) {:action=>"destroy", :controller=>"admin/pages"} pages_path admin_pages_path edit_page_path(id) edit_admin_page_path(id)
  33. 33. config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to => "welcome#index"    resources :pages do    resources :comments  endend http://localhost:3000/pages/2/comments
  34. 34. rake routes... page_comments GET /pages/:page_id/comments(.:format) {:action=>"index", :controller=>"comments"} POST /pages/:page_id/comments(.:format) {:action=>"create", :controller=>"comments"} new_page_comment GET /pages/:page_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}edit_page_comment GET /pages/:page_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"} page_comment GET /pages/:page_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"} PUT /pages/:page_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"} DELETE /pages/:page_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"} comments_path page_comments_path(page_id) edit_comment_path(id) edit_page_comment_path(page_id, id)
  35. 35. config/routes.rbRails3dojo::Application.routes.draw do  # You can have the root of your site routed with "root"  root :to => "welcome#index"    resources :pages do    get freeze, :on => :collection    get preview, :on => :member  endend http://localhost:3000/pages/freeze http://localhost:3000/pages/2/preview
  36. 36. rake routes(in /Users/kato/sandbox/rails3dojo) root /(.:format) {:controller=>"welcome", :action=>"index"}freeze_pages GET /pages/freeze(.:format) {:action=>"freeze", :controller=>"pages"}preview_page GET /pages/:id/preview(.:format) {:action=>"preview", :controller=>"pages"} pages GET /pages(.:format) {:action=>"index", :controller=>"pages"} POST /pages(.:format) {:action=>"create", :controller=>"pages"} new_page GET /pages/new(.:format) {:action=>"new", :controller=>"pages"} edit_page GET /pages/:id/edit(.:format) {:action=>"edit", :controller=>"pages"} page GET /pages/:id(.:format) {:action=>"show", :controller=>"pages"} PUT /pages/:id(.:format) {:action=>"update", :controller=>"pages"} DELETE /pages/:id(.:format) {:action=>"destroy", :controller=>"pages"} freeze_pages_path preview_page_path(id)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×