Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where the devise_for was being placed below the mounted engine in routes.rb #1335

Merged
merged 3 commits into from
Sep 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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