Why is my rails route is a bit off?

别来无恙 提交于 2019-12-23 15:18:07

问题


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"}

回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/7669780/why-is-my-rails-route-is-a-bit-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!