Resource-Based Routing
基本增加的内容
Resource-Based Routing依靠restful的风格,定义后增加下面4个helper
client_url show update destroy
clients_url index create
edit_client_url edit
new_client_url new
update和destroy通过传入:method来完成
对于link_to form_tag可直接在client_url后面跟着:method => :delete
对于form_for来说,会要求跟在一个嵌套hash中 form_for @client, :html => {:method=>:delete}
单复数route
两种使用helper的形式
client_url(@item) ----参数形式
clent_url(:id => @item) ----hash形式
定义自己的action
map.resources :articles, :collection
=> { :recent => :get }
:collection增加了recent action包括
Method: get
path: /articles/recent
action: recent
helper: recent_articles_url
:member
则给某个实例增加action
map.resources :articles, :member => {:release => :put, :rollback => :put}
Method: put
path: /articles/1/release
action: release
helper: release_article_url
Nested Resources
有些资源有依赖关系,需要成对出现
嵌套定音的后果
map.resources :auctions do |auction|
auction.resources :bids
end
除了autions的4个helper,也为bids定义了auction_bids_url, new_auction_bid_url等等helper。
nested 使得任何使用bid routes的时候,必须提供auction资源
对于singular routes需要提供至少两个参数
:name_perfix 使得可以定义helper的前缀
用nil表示取消前缀
对于form_for可以采用
<% form_for([:admin, @post]) do |f| %>
上一篇: mysql中的事务隔离级别
下一篇: scf跑起来
推荐阅读
-
7.ASP.NET MVC 5.0中的Routing【路由】
-
ASP.NET MVC Routing、Areas、URLs
-
RabbitMQ指南之四:路由(Routing)和直连交换机(Direct Exchange)
-
详解ASP.NET Core MVC 源码学习:Routing 路由
-
在IIS7中应用Application Request Routing配置反向代理的图文教程
-
spring boot中使用RabbitMQ routing路由详解
-
.NET/ASP.NET Routing路由(深入解析路由系统架构原理)
-
简单讲解AngularJS的Routing路由的定义与使用
-
ASP.NET 中使用 Routing 进行 URL 优化,规则中的 .html 不起作用的解决方法
-
ASP.NET Core MVC学习教程之路由(Routing)