Error routing caused by 'redirect_to root_url' not passing action

With a standard installation of Rails_Admin, which uses authentication for authentication and CanCan, accessing http: // localhost: 3000 / admin as a non-administrator user creates the following server log:

Started GET "/admin" for 127.0.0.1 at 2011-08-09 22:46:10 -0400
  Processing by RailsAdmin::MainController#index as HTML
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Completed 404 Not Found in 151ms

ActionController::RoutingError (No route matches {:controller=>"gyms"}):
  app/controllers/application_controller.rb:5:in `block in <class:ApplicationController>'

Everything to the last part looks fine. As far as I can tell, CanCan correctly eliminates the exception and tries to redirect to root_url using the following code:

class ApplicationController < ActionController::Base
  protect_from_forgery

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end
end

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

  resources :gyms

  root :to => "gyms#index"
end

But for some reason, when redirecting to root_url, CanCan only tries to click

{:controller=>"gyms"}

but not

{:controller=>"gyms", :action=>"index"}

Perhaps this is a problem with CanCan? Or is there some specific aspect of redirect_to or root_url that I skipped in the docs?

. , Canitan github, , .

+5
1

Github, , name_scoped, .

- root_url main_app :

rescue_from CanCan::AccessDenied do |exception|
  redirect_to main_app.root_url, :alert => exception.message
end

bbenezech https://github.com/sferik/rails_admin/issues/658

+6

All Articles