Why is my rail route a bit off?

I have my root route

root :to => 'home#index' 

which is for my home controller, and if I visit http://localhost:3000/ , everything works fine, I find the correct home controller and index action. Then I installed this gem rails_admin But when I visit http://localhost:3000/admin , I find 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"} 
+4
source share
3 answers

I think the problem lies in the fact that in the rails_admin engine there is no main controller that has its own routing, and somehow it stops there (because there is no such controller). I would try using:

 redirect_to root_url 

or even that

 redirect_to '/' 

This last method means that the rails should not try to determine the path by calling the URL, and can be more secure when working with engines.

+3
source

If you reference the routes of your application inside your engine or config/initializers/rails_admin.rb , you must prefix it with main_app.

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

+4
source

It looks like your main controller is undefined.

Try adding this above your definition of "root":

 resources :home, :only => :index 

I also suggest reading the official route guide on the Rails website.

-1
source

All Articles