Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Rails 开发入门课程] 第四节 Routes

[Rails 开发入门课程] 第四节 Routes

这一节主要介绍 Routes:如何把一个 URL 和 Controller#Action 对应起来。

David Zhang

January 15, 2013
Tweet

More Decks by David Zhang

Other Decks in Programming

Transcript

  1. RAILS 开发⼊入⻔门课程 RAILS 运⾏行环境 Model Routes 第⼀一节 第⼆二节 第四节 Controllers

    & Views 第五节 ActiveRecord Association 第六节 Form API 第三节 13年1月17⽇日星期四
  2. 内容回顾 浏览器 Web Server App Server DB Rails API HTTP

    请求处理流程 13年1月17⽇日星期四
  3. The concept of resource has evolved during the Web history,

    from the early notion of static addressable documents or files, to a more generic and abstract definition, now encompassing every thing or entity that can be identified, named, addressed or handled, in any way whatsoever, in the Web at large, or in any networked information system. 13年1月17⽇日星期四
  4. topic http://example.com/topics GET http://example.com/topics POST http://example.com/topics/101 GET http://example.com/topics/101 PUT http://example.com/topics/new

    GET http://example.com/topics/101/edit GET http://example.com/topics/101 DELETE collection member 13年1月17⽇日星期四
  5. /topics GET /topics POST /topics/:id/edit GET /topics/:id PUT /topics/new GET

    /topics/:id GET /topics/:id DELETE $ rake routes topics new_topics edit_topics topic topics#index topics#create topics#new topics#edit topics#show topics#update topics#destroy 13年1月17⽇日星期四
  6. /topics GET /topics/:id DELETE topics topics#index topics#destroy topic link_to ‘all

    topics’, topics_path link_to ‘all topics’, topics_url link_to ‘delete’, topic_path(@topic), :method => :delete link_to ‘delete’, topic_url(@topic), :method => :delete 13年1月17⽇日星期四
  7. /topics/:id/close PUT /topics/hot GET $ rake routes close_topic hot_topics topics#hot

    topics#close link_to ‘close this topic’, close_topic_path(@topic) link_to ‘hot topics’, hot_topics 13年1月17⽇日星期四
  8. /topics/:topic_id/comments GET POST GET PUT GET GET DELETE $ rake

    routes topic_comments new_topic_comment edit_topic_comment topic_comment comments#index comments#create comments#new comments#edit comments#show comments#update comments#destroy /topics/:topic_id/comments /topics/:topic_id/comments/new /topics/:topic_id/comments/:id/edit /topics/:topic_id/comments/:id /topics/:topic_id/comments/:id /topics/:topic_id/comments/:id 13年1月17⽇日星期四