tcz
May 21, 2007, 9:14pm
1
Jesli uzywasz ‘resources’ to moze sie przydac.
Umiesc poniższy kod w ‘lib/tasks/’ , nazwij go np. named_routes.rake
Następnie użyj ‘rake named_routes’
desc "Listuj wszystkie routes"
task :named_routes => :environment do
ActionController::Routing::Routes.named_routes.routes.each do |name, route|
puts "%20s: %s" % [name, route]
end
end
Powyzszy rake task wylistuje wszystkie ‘routes’ zdefiniowane w routes.rb
tcz
May 21, 2007, 9:18pm
2
Dodam jeszcze inny podobny do powyzszego.
Podobnie, umiesc ten kod w ‘lib/tasks/’ i dodolna nazwa np. routes_map.rake
Nastepnie uzyj za pomoca ‘rake routes_map’
desc "Listuj wszystkie routes"
task :routes => :environment do
puts ActionController::Routing::Routes.routes.map { |r|
sprintf "%30s => %s", r.path.inspect, r.known.inspect
} rescue puts ActionController::Routing::Routes.routes
end
tcz
September 1, 2007, 4:10pm
3
Jakis czas temu znalazlem taka wersje. Mysle, ze sie wam przyda.
Prawdopodbnie jest to wersja, ktora bedzie czescia railsow.
desc 'Pokaz sortowana liste routes.'
task :routes => :environment do
routes = ActionController::Routing::Routes.routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
verb = route.conditions[:method].to_s.upcase
segs = route.segments.inject("") { |str,s| str << s.to_s }
segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
{:name => name, :verb => verb, :segs => segs, :reqs => reqs}
end
name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
routes.each do |r|
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
end
end
mazzy
October 28, 2007, 12:18pm
4
A nie lepiej po prostu wpisac “rake routes” (jesli jedziecie na edge)?
tcz
October 28, 2007, 5:59pm
5
Tak dokladnie, routes.rake jest cześcią railsów od 1.2.4
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/tasks/routes.rake
Pozdrawiam