Skip to content
This repository
Browse code

remove old routing hack. replace with Clearance::Routes.draw(map) to …

…give more control to the application developer.
  • Loading branch information...
commit 8f355a3f96ec9323d7f87da7fbe298ecefbddf1e 1 parent c73d1df
Dan Croak croaky authored
6 TODO.textile
Source Rendered
... ... @@ -1,6 +0,0 @@
1   -h1. To-do
2   -
3   -* Make insertion of Clearance::User into User model automatic from the generator.
4   -* Change generated README to include instruction about running the migration.
5   -* DO_NOT_REPLY, HOST refactoring.
6   -
30 config/clearance_routes.rb
... ... @@ -1,30 +0,0 @@
1   -ActionController::Routing::Routes.draw do |map|
2   - map.resources :passwords,
3   - :controller => 'clearance/passwords',
4   - :only => [:new, :create]
5   -
6   - map.resource :session,
7   - :controller => 'clearance/sessions',
8   - :only => [:new, :create, :destroy]
9   -
10   - map.resources :users, :controller => 'clearance/users' do |users|
11   - users.resource :password,
12   - :controller => 'clearance/passwords',
13   - :only => [:create, :edit, :update]
14   -
15   - users.resource :confirmation,
16   - :controller => 'clearance/confirmations',
17   - :only => [:new, :create]
18   - end
19   -
20   - map.sign_up 'sign_up',
21   - :controller => 'clearance/users',
22   - :action => 'new'
23   - map.sign_in 'sign_in',
24   - :controller => 'clearance/sessions',
25   - :action => 'new'
26   - map.sign_out 'sign_out',
27   - :controller => 'clearance/sessions',
28   - :action => 'destroy',
29   - :method => :delete
30   -end
2  lib/clearance.rb
... ... @@ -1,6 +1,6 @@
1 1 require 'clearance/extensions/errors'
2 2 require 'clearance/extensions/rescue'
3   -require 'clearance/extensions/routes'
4 3
  4 +require 'clearance/routes'
5 5 require 'clearance/authentication'
6 6 require 'clearance/user'
14 lib/clearance/extensions/routes.rb
... ... @@ -1,14 +0,0 @@
1   -if defined?(ActionController::Routing::RouteSet)
2   - class ActionController::Routing::RouteSet
3   - def load_routes_with_clearance!
4   - lib_path = File.dirname(__FILE__)
5   - clearance_routes = File.join(lib_path, *%w[.. .. .. config clearance_routes.rb])
6   - unless configuration_files.include?(clearance_routes)
7   - add_configuration_file(clearance_routes)
8   - end
9   - load_routes_without_clearance!
10   - end
11   -
12   - alias_method_chain :load_routes!, :clearance
13   - end
14   -end
49 lib/clearance/routes.rb
... ... @@ -0,0 +1,49 @@
  1 +module Clearance
  2 + class Routes
  3 +
  4 + # In your application's config/routes.rb, draw Clearance's routes:
  5 + #
  6 + # @example
  7 + # map.resources :posts
  8 + # Clearance::Routes.draw(map)
  9 + #
  10 + # If you need to override a Clearance route, invoke your app route
  11 + # earlier in the file so Rails' router short-circuits when it finds
  12 + # your route:
  13 + #
  14 + # @example
  15 + # map.resources :users, :only => [:new, :create]
  16 + # Clearance::Routes.draw(map)
  17 + def self.draw(map)
  18 + map.resources :passwords,
  19 + :controller => 'clearance/passwords',
  20 + :only => [:new, :create]
  21 +
  22 + map.resource :session,
  23 + :controller => 'clearance/sessions',
  24 + :only => [:new, :create, :destroy]
  25 +
  26 + map.resources :users, :controller => 'clearance/users' do |users|
  27 + users.resource :password,
  28 + :controller => 'clearance/passwords',
  29 + :only => [:create, :edit, :update]
  30 +
  31 + users.resource :confirmation,
  32 + :controller => 'clearance/confirmations',
  33 + :only => [:new, :create]
  34 + end
  35 +
  36 + map.sign_up 'sign_up',
  37 + :controller => 'clearance/users',
  38 + :action => 'new'
  39 + map.sign_in 'sign_in',
  40 + :controller => 'clearance/sessions',
  41 + :action => 'new'
  42 + map.sign_out 'sign_out',
  43 + :controller => 'clearance/sessions',
  44 + :action => 'destroy',
  45 + :method => :delete
  46 + end
  47 +
  48 + end
  49 +end
5 test/rails_root/config/routes.rb
... ... @@ -1,5 +1,6 @@
1 1 ActionController::Routing::Routes.draw do |map|
2   - map.resource :account
3   -
  2 + map.resource :account
4 3 map.root :controller => 'accounts', :action => 'edit'
  4 +
  5 + Clearance::Routes.draw(map)
5 6 end

0 comments on commit 8f355a3

Please sign in to comment.
Something went wrong with that request. Please try again.