如何将URL字符串解析为哈希值,例如
{:controller => 'controller_name', :action => 'action_name', :id => 'id'}
如何将URL字符串解析为哈希值,例如
{:controller => 'controller_name', :action => 'action_name', :id => 'id'}
在Rails 3中,您可以执行以下操作:
Rails.application.routes.recognize_path "/accounts/1"
# {:action=>"show", :controller=>"accounts", :id=>"1"}
使用ActionController::Routing::Routes.recognize_path时,始终抛出ActionController::RoutingError异常:没有匹配"/accounts/1"的路由。根据URL的格式,您可以尝试使用ActionController::Routing::Routes.recognize_path
:
>> ActionController::Routing::Routes.recognize_path("/accounts/1",:method=>:get)`
# {:action=>"show":controller=>"accounts",:id=>"1"}