Skip to content

Commit

Permalink
Merge pull request #1335 from cavneb/master
Browse files Browse the repository at this point in the history
Fixed bug where the devise_for was being placed below the mounted engine in routes.rb
  • Loading branch information
sferik committed Sep 26, 2012
2 parents 8e2bff0 + 70b5115 commit 3a0b832
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -83,19 +83,19 @@ It will modify your `config/routes.rb`, adding:
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin' # Feel free to change '/admin' to any namespace you need.
```

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

```ruby
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
devise_for :admins
```

Consider renaming your RailsAdmin namespace:
This will resolve the infinite redirect error:

```ruby
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
devise_for :admins
mount RailsAdmin::Engine => '/rails_admin', :as => 'rails_admin'
```

See [#715](https://github.com/sferik/rails_admin/issues/715) for more details.
Expand Down
7 changes: 4 additions & 3 deletions lib/generators/rails_admin/install_generator.rb
Expand Up @@ -37,6 +37,10 @@ def install
display "Looks like you've already installed it, good!"
end

namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")

unless routes.index("devise_for")
model_name = ask_for("What would you like the user model to be called?", "user", _model_name)
display "Now setting up devise with user model name '#{model_name}':"
Expand Down Expand Up @@ -75,9 +79,6 @@ def install
end
display "Adding a migration..."
migration_template 'migration.rb', 'db/migrate/create_rails_admin_histories_table.rb' rescue display $!.message
namespace = ask_for("Where do you want to mount rails_admin?", "admin", _namespace)
gsub_file "config/routes.rb", /mount RailsAdmin::Engine => \'\/.+\', :as => \'rails_admin\'/, ''
route("mount RailsAdmin::Engine => '/#{namespace}', :as => 'rails_admin'")
display "Job's done: migrate, start your server and visit '/#{namespace}'!", :blue
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/config/routes.rb
Expand Up @@ -2,8 +2,8 @@
# Needed for :show_in_app tests
resources :players, :only => [:show]

mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
devise_for :users
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
root :to => "rails_admin::Main#dashboard"
# https://github.com/sferik/rails_admin/issues/362
match ':controller(/:action(/:id(.:format)))'
Expand Down

0 comments on commit 3a0b832

Please sign in to comment.