基本增加的内容
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| %>