Rails:从URL解析路由信息

###在Rails 3中,您可以执行以下操作:
Rails.application.routes.recognize_path "/accounts/1" # {:action=>"show", :controller=>"accounts", :id=>"1"}

  

### 默认method => get
url = ActionController::Routing::Routes.recognize_path("/accounts/1",:method=>:get)` # {:action=>"show":controller=>"accounts",:id=>"1"}

#################################################################
### 默认method => get
url = Rails.application.routes.recognize_path(request.referrer, method: "get")
last_controller = url[:controller]
last_action = url[:action]

  

posted @ 2023-05-23 13:14  鞋带松了  阅读(12)  评论(0编辑  收藏  举报