Skip to content

Commit 3a0b832

Browse files
committed
Merge pull request #1335 from cavneb/master
Fixed bug where the devise_for was being placed below the mounted engine in routes.rb
2 parents 8e2bff0 + 70b5115 commit 3a0b832

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ It will modify your `config/routes.rb`, adding:
8383
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin' # Feel free to change '/admin' to any namespace you need.
8484
```
8585

86-
Note: Your RailsAdmin namespace cannot match your Devise model name, or you will get an infinite redirect error.
86+
Note: The `devise_for` route must be placed before the mounted engine. The following will generate infinite redirects.
8787
The following will generate infinite redirects.
8888

8989
```ruby
9090
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
9191
devise_for :admins
9292
```
9393

94-
Consider renaming your RailsAdmin namespace:
94+
This will resolve the infinite redirect error:
9595

9696
```ruby
97-
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
9897
devise_for :admins
98+
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
9999
```
100100

101101
See [#715](https://github.com/sferik/rails_admin/issues/715) for more details.

lib/generators/rails_admin/install_generator.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def install
3737
display "Looks like you've already installed it, good!"
3838
end
3939

40+
namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
41+
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
42+
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
43+
4044
unless routes.index("devise_for")
4145
model_name = ask_for("What would you like the user model to be called?", "user", _model_name)
4246
display "Now setting up devise with user model name '#{model_name}':"
@@ -75,9 +79,6 @@ def install
7579
end
7680
display "Adding a migration..."
7781
migration_template 'migration.rb', 'db/migrate/create_rails_admin_histories_table.rb' rescue display $!.message
78-
namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
79-
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
80-
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
8182
display "Job's done: migrate, start your server and visit '/#{namespace}'!", :blue
8283
end
8384
end

spec/dummy_app/config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Needed for :show_in_app tests
33
resources :players, :only => [:show]
44

5-
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
65
devise_for :users
6+
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
77
root :to => "rails_admin::Main#dashboard"
88
# https://github.com/sferik/rails_admin/issues/362
99
match ':controller(/:action(/:id(.:format)))'

0 commit comments

Comments
 (0)