Rutes a la consola
Per a depurar les rutes mitjançant la consola de Rails:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
$ script/console
Loading development environment.
# Carreguem la definició de les rutes
>> rs = ActionController::Routing::Routes
=> #<actioncontroller::routing::routeset:0x61d76c>> puts rs.routes
ANY /feed/suggest/ {:action=>"suggest", :controller=>"public"}
ANY /feed/thanks/ {:action=>"thanks", :controller=>"public"}
ANY /:page/ {:action=>"index", :controller=>"public"}
ANY /:controller/:action/:id.:format/ {}
ANY /:controller/:action/:id/ {}
=> nil
# Reconeixement de rutes
>> rs.recognize_path "/feed"
=> {:action=>"index", :page=>"feed", :controller=>"public"}
>> rs.recognize_path "/feed/thanks"
=> {:action=>"thanks", :controller=>"public"}
>> rs.generate :controller => :public, :page => 2
=> "/2"
# Per a testejar rutes de controladors inexistents
>> ActionController::Routing.use_controllers! [ "undefined", "test" ]
=> ["undefined", "test"]
>> load "config/routes.rb"
=> []
>> rs.recognize_path "/undefined/show/1"
=> {:action=>"show", :id=>"1", :controller=>"undefined"} |

