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| %>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值