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

Redirect loop when visiting /admin #715

Closed
andypike opened this issue Sep 13, 2011 · 13 comments
Closed

Redirect loop when visiting /admin #715

andypike opened this issue Sep 13, 2011 · 13 comments

Comments

@andypike
Copy link

Hi all,

I've just installed rails_admin for the first time and have hit a bit of a snag. After installation I go to /admin and I end up in a redirection loop. When Chrome displays the error the url in the address bar is: /admin_users/sign_in

Firstly, during the install I had a problem with Devise. I think the gem 'devise' line was added to the end of my gemfile but without a new line and so it was appended to and closing block end (eg: endgem 'devise') which caused problems for the rails_admin install process. I got through that and updated devise manually afterwards.

I'm also user a custom user model of admin_user as I already have a user model that I don't want to allow access to rails_admin.

I haven't done any other customization from the default install. But I get the redirection loop if I go to /admin. I've checked over everything and it all looks good (as far as I can tell).

I can get it to work if I edit the rails_admin initializer to include an empty config.authenticate_with block. But of course this means there isn't any authentication and anyone can see the admin panel.

Any ideas to point me in the right direction? This might be related to the failed initial install but I think I covered everything.

Thanks in advance

Andy

@bbenezech
Copy link
Collaborator

You just need to set current_user_method so that RA knows which user to use, that's all. Check your initializer.
You get a redirection loop maybe because your root url isn't set or is set to /admin?

Can you give me your Gemfile, so I can see why Thor screwed up with the gem 'devise'?

@andypike
Copy link
Author

Hi, thanks for the fast reply!

This is setup in my initializer:

config.current_user_method { current_admin_user }.

Do I need to implement the current_admin_user method? I thought that was supplied by devise but I might be mistaken? Also, I do have a root_url setup, here is a stripped down routes.rb that has the same problem:

Brewster::Application.routes.draw do  
  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
  devise_for :admin_users

  root :to => 'pages#home'
end

Regarding the gemfile, here it is with the devise reference moved down onto a newline:

source 'http://rubygems.org'

gem 'rails', '3.1.0'
gem 'simple_form'
gem 'haml-rails'
gem 'jquery-rails'
gem 'cancan'
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

group :test do
  gem 'turn', :require => false
  gem 'cucumber-rails'
  gem 'database_cleaner'
  gem 'shoulda'
  gem 'launchy'
  gem 'simplecov', '>= 0.4.0', :require => false
end

group :test, :development do
  gem "rspec-rails"
  gem 'sqlite3'
  gem 'fabrication'
end

group :development do
  gem 'pry' # To use pry with the rails console use: $ pry -r ./config/environment
            # To debug, add the following in source code: 
            # => binding.pry 
            # then go to the webserver terminal (see http://railscasts.com/episodes/280-pry-with-rails)
end
gem "devise"

Any thing I can try to debug the problem? Sorry for being a n00b.

@pollingj
Copy link

I'm also having this issue with a fresh install. My model is called 'admin', but other than that I'm exactly the same as above.

@pollingj
Copy link

Ok, think I've spotted it. When I had the Rails::Engine pointing towards '/admin' and the devise_for :admins the model the route it was attempting to go to was /admins/sign_in which was trying to hit this

Processing by RailsAdmin::MainController#show as HTML Parameters: {"model_name"=>"s", "id"=>"sign_in"}

So it looks like Rails Admin is greedily grabbing anything with the word /admin in it's path. As soon as I changed the rails admin path to /cms everything worked fine.

@bbenezech
Copy link
Collaborator

What if you put RA route after devise :admins?
Is it the same?

@andypike
Copy link
Author

I just tried out the suggestion by @pollingj and that works great. I spotted a similar message in the server logs but mine was:

Processing by RailsAdmin::MainController#show as HTML
Parameters: {"model_name"=>"_users", "id"=>"sign_in"} 

I assumed the _users was how rails_admin worked. Anyway, I've also moved the RA route so it's under the devise route and that also works with /admin.

Thanks guys for the help :o)

@bbenezech
Copy link
Collaborator

Ok, not a RA issue, then.. Just the way Rack::Mount works. I thought it would match /admin/ instead of /admin...

@iRonin
Copy link

iRonin commented Jun 4, 2012

I've just run with the same issue when using admin model. If I put devise_for :admin before RA it works.

@Alexander-Senko
Copy link
Contributor

I have this in routes.rb:

    devise_for :users
    devise_for :staff,     :class_name => 'User::Staff'
    devise_for :customers, :class_name => 'User::Customer'

    mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

User::* descend from User.

How to use User::Staff for RA? Now /admin redirects to / on 401 Unauthorized.

@Alexander-Senko
Copy link
Contributor

Got it! Should use this code:

    devise_for :staff,     :class_name => 'User::Staff'
    devise_for :customers, :class_name => 'User::Customer'
    devise_for :users

    mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

RA uses the first devise_for. But maybe Devise itself behaves so, not RA.

@pehrlich
Copy link

Awesome, thanks for posting this.

@BartlomiejSkwira
Copy link

Suffered from same problem, @iRonin's simple solution to switch lines helped me. I've added this info to the Troubleshooting wiki

@kidlab
Copy link

kidlab commented Mar 11, 2015

Yeah, I got this problem too. @iRonin's solution works! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants