Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature mount_sextant for counteract catch-all route method #9

Merged
merged 6 commits into from

2 participants

@menkel

Based on #1

I propose a method to define the routes of sextant in routes.rb for users who used the catch-all route in routes.rb .

Gem's routes are define after the routes.rb that's why we need to write something in routes.rb,
you have just to write mount_sextant before all catch-all route :

mount_sextant
match '*not_found' => 'errors#handle404'
match "*path" => 'errors#handle404'
lib/sextant/engine.rb
@@ -1,5 +1,9 @@
module Sextant
class Engine < Rails::Engine
isolate_namespace Sextant
+
+ initializer "Sextant mount routes" do
+ ActionDispatch::Routing::Mapper.send(:include, Sextant::Routing)
@schneems Owner

Not sure we need a DSL for this, how does devise get their devise_for routes into the proper object?

@menkel
menkel added a note

Thank you for your advice.
Devise use the class Mapper of ActionDispatch::Routing module for create devise_for.
I will follow this new way.
cf. https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@menkel

I have rewritten the implementation of mount_sextant based on devise_for.

@schneems schneems merged commit c5d40d1 into schneems:master
@schneems
Owner

Thanks

@menkel

It was my first pull request :)

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
9 README.md
@@ -30,6 +30,15 @@ end
Then run `bundle install` and you're ready to start
+### Optional for user of catch-all route in routes.rb:
+
+Add sextant to your routes (config/routes.rb) before catch-all routes
+
+```ruby
+mount_sextant
+match '*not_found' => 'errors#handle404'
+match "*path" => 'errors#handle404'
+```
## Use
View
6 config/routes.rb
@@ -1,9 +1,7 @@
Rails.application.routes.draw do
- namespace :rails do
- resources :routes, :only => [:index, :show]
- end
+ mount_sextant
end
# RouteInspector::Engine.routes.draw do
-#
+#
# end
View
11 lib/rails/routes.rb
@@ -0,0 +1,11 @@
+module ActionDispatch::Routing
+ class Mapper
+ # Includes mount_sextant method for routes. This method is responsible to
+ # generate all needed routes for sextant
+ def mount_sextant
+ namespace :rails do
+ resources :routes, :only => [:index, :show]
+ end
+ end
+ end
+end
View
1  lib/sextant.rb
@@ -1,5 +1,6 @@
require 'rails/application/route_inspector'
require 'sextant/engine'
+require 'rails/routes'
module Sextant
def self.format_routes(routes = all_routes)
View
4 test/dummy/app/controllers/foo_controller.rb
@@ -0,0 +1,4 @@
+class FooController < ApplicationController
+ def index
+ end
+end
View
4 test/dummy/app/foo_controller.rb
@@ -0,0 +1,4 @@
+class FooController < ApplicationController
+ def index
+ end
+end
View
0  test/dummy/app/views/foo/index.html
No changes.
View
3  test/dummy/config/routes.rb
@@ -2,6 +2,9 @@
resources :foo
resources :bar
+ mount_sextant
+
+ match '*a', :to => 'foo#index'
# The priority is based upon order of creation:
# first created -> highest priority.
Something went wrong with that request. Please try again.