Rails3.1
RailsGuides   Routing
2012/01/21 @akimatter
RBC                @akimatter

                   https://github.com/akm
      Ruby/Rails
 6                 http://d.hatena.ne.jp/akm/
agenda
EC                 URL
REST
 REST
 HTTP
 Rails   REST
HandsOn
 RailsGuides
 config/routes.rb
 Rails
EC
URL
EC




     /
REST
REST
REST
Representational State Transfer

“REST
          (       )
                                       REST
                           2
          ”

http://ja.wikipedia.org/wiki/REST


                                    AWS API
REST   URL



URL

URL    HTTP
REST


 GET

DELETE

 PUT

POST

       http://www.infoq.com/jp/articles/designing-
 restful-http-apps-roth
HTTP
HTTP


Chrome developer tool

 GET     POST
HTTP

RFC2616 9

http://www.studyinghttp.net/cgi-bin/rfc.cgi?
2616#Sec9

  GET, POST           OPTIONS, HEAD, PUT,
  DELETE, TRACE, CONNECT

               GET, HEAD, POST
http://www.studyinghttp.net/cgi-bin/rfc.cgi?
2616#Sec9.1.1




      GET HEAD
{idempotent}


http://ja.forvo.com/word/idempotent/

“




http://www.studyinghttp.net/cgi-bin/rfc.cgi?2616#Sec9.1.2
“                                   :
idempotence
                                1


         ”

http://ja.wikipedia.org/wiki/
ID




DB        OK
Rails   REST
RESTful

              scaffold
                RESTful

  RESTful URL

rake routes
scaffold

           index            .all
            new            .new
           create       .new #save
           show          .find(:id)
            edit         .find(:id)
           update     .find(:id) #save
           destroy   .find(:id) #destroy
URL
        users
      Rails1.x              Rails2.0
     RESTful URL                   RESTful URL
/users/index          GET        /users            index
/users/new            GET        /users/new         new
/users/create        POST        /users            create
/users/show/:id       GET        /users/:id        show
/users/edit/:id       GET        /users/:id/edit    edit
/users/update/:id     PUT        /users/:id        update
/users/destroy/:id   DELETE      /users/:id        destroy

    :id                     ID
HandsOn
RailsGuides
Rails Routing from the Outside In

     ruby/rails/RailsGuides         /Rails

Routing from the Outside In
#1

rails
  rails new <   >



  rake routes
#2


rails generate scaffold <       >
<        1>:< > <         2>:< > ...
   rails g scaffold Photo
 image_path:string size:integer
#3
DB
 rake db:migrate



 rails server



 rails c
HandsOn
config/routes.rb
config/routes.rb
HandsOn
rails
config/routes.rb

20120121 rbc rails_routing