我有一个资源定义如下:
resources :referrals, :except => [:show, :edit, :destroy]我希望将Rails生成的默认路由替换(不仅仅是添加指定的路由),特别是为update操作创建的路由。
这是我的耙路:
referrals GET /referrals(.:format) {:action=>"index", :controller=>"referrals"}
POST /referrals(.:format) {:action=>"create", :controller=>"referrals"}
new_referral GET /referrals/new(.:format) {:action=>"new", :controller=>"referrals"}
referral PUT /referrals/:id(.:format) {:action=>"update", :controller=>"referrals"}
share /share(.:format) {:controller=>"referrals", :action=>"new"}
special /special(.:format) {:controller=>"referrals", :action=>"index"}
thanks /thanks(.:format) {:controller=>"pages", :action=>"thanks"}
/:shortlink(.:format) {:controller=>"referrals", :action=>"update"}
/:linktext(.:format) {:controller=>"referrals", :action=>"update"}
root /(.:format) {:controller=>"pages", :action=>"home"}我想要么
/:shortlink(.:format)或
/:linktext(.:format)若要单击update操作,请执行以下操作:
/referrals/:id(.:format)这是为了实现一种非密码形式的“安全性”。当PUT转到update操作时,我希望发生某些事情,但我不想要求授权才能这样做,我不想允许根据控制器名称和简单的低编号ids轻松猜测url。
我怎样才能完全用替换-- rails给出的默认路由?
发布于 2012-03-29 19:37:03
resources :referrals, :except => [:show, :edit, :destroy, :update]
match "/whatever_you_want/:variable_here" => "referrals#updated", :as=> the_link, :via=> :put
然后在您的控制器中,您将访问
params[:variable_here]
在这里,param是您想要在db中与之比较的任何内容,路径将创建如下所示:
the_link_path或the_link_url
:via部件将约束每个HTTP方法的路径,因此只有put请求才匹配
更多信息请访问http://guides.rubyonrails.org/routing.html
https://stackoverflow.com/questions/5491199
复制相似问题