Question

I have my root route

root :to => 'home#index'

which is for my home controller and if i visit http://localhost:3000/ all works great i hit the proper home controller and index action. I then installed this gem rails_admin But when i visit http://localhost:3000/admin i hit the method in my application controller

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

and get this error, how is it possible that now i have a routing error...any idea

Routing Error

No route matches {:controller=>"home"}
Was it helpful?

Solution

I think the problem lies in that there's no HomeController in the rails_admin engine which has it's own routing, and somehow it stops there (because there's no such controller in the engine). I'd try using:

redirect_to root_url

or even this

redirect_to '/'

This last way means rails doesn't have to try to figure out the path by calling URL for, and might be safer when working with Engines.

OTHER TIPS

If you are referencing your app's routes inside your engine or config/initializers/rails_admin.rb, you should prefix it with main_app.

redirect_to main_app.root_path, :alert => exception.message

It looks like you don't have your Home Controller defined.

Try adding this above your "root" definition:

resources :home, :only => :index

I'd also suggest reading the official Routes guide on the Rails site.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top