From 31aad2d2d272bb98606174f66d18d7110a3c6c86 Mon Sep 17 00:00:00 2001 From: Jacek Tomaszewski Date: Wed, 25 Sep 2013 21:11:22 +0200 Subject: [PATCH] Add support for relative_url_root option. This solves problem if you have set your application to be run on relative url like "/url/" (`config.action_controller.relative_url_root` option). --- app/views/api_taster/routes/show.html.erb | 2 +- lib/api_taster/route.rb | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/views/api_taster/routes/show.html.erb b/app/views/api_taster/routes/show.html.erb index 2825259..eeab34f 100644 --- a/app/views/api_taster/routes/show.html.erb +++ b/app/views/api_taster/routes/show.html.erb @@ -16,7 +16,7 @@ <% end %> <% @params.each do |param| %> - <%= form_tag @route[:path], :method => @route[:verb], :class => 'well form-horizontal', :remote => true do %> + <%= form_tag @route[:full_path], :method => @route[:verb], :class => 'well form-horizontal', :remote => true do %> <% if param[:url_params].empty? && param[:post_params].empty? %>
diff --git a/lib/api_taster/route.rb b/lib/api_taster/route.rb index e36c0ab..e0acfbf 100644 --- a/lib/api_taster/route.rb +++ b/lib/api_taster/route.rb @@ -116,12 +116,14 @@ def discover_rack_app(app) def normalise_route(route, path_prefix = nil) route.verb.source.split('|').map do |verb| + path = path_prefix.to_s + route.path.spec.to_s.sub('(.:format)', '') { - :id => @_route_counter+=1, - :name => route.name, - :verb => verb.gsub(/[$^]/, ''), - :path => path_prefix.to_s + route.path.spec.to_s.sub('(.:format)', ''), - :reqs => route.requirements + :id => @_route_counter+=1, + :name => route.name, + :verb => verb.gsub(/[$^]/, ''), + :path => path, + :full_path => rails_url_root + path, + :reqs => route.requirements } end end @@ -143,6 +145,10 @@ def hash_diff(h1, h2) h2[k] == v end.merge!(h2.dup.delete_if { |k, v| h1.has_key?(k) }) end + + def rails_url_root + ActionController::Base.relative_url_root.to_s.chomp('/') + end end end end