Skip to content

Commit

Permalink
Add support for relative_url_root option.
Browse files Browse the repository at this point in the history
This solves problem if you have set your application to be run on relative url like "/url/"
(`config.action_controller.relative_url_root` option).
  • Loading branch information
jtomaszewski committed Sep 25, 2013
1 parent a1561f5 commit 31aad2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/views/api_taster/routes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
<div class="alert alert-info">
Expand Down
16 changes: 11 additions & 5 deletions lib/api_taster/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 31aad2d

Please sign in to comment.