Weird route malfunction, mix between devise and own controller

為{幸葍}努か 提交于 2019-12-24 07:58:01

问题


I've got a real weird route behavior. I spotted the line which, i think, cause the error.
Here is the line (in application.html.erb) in question :

<%= link_to "Official Top", :controller => "tops", :action => "show", :id => 10 %>

The problem happens when i want to sign in with devise, when i go to this link :

http://localhost:3000/users/sign_in 
using <%= link_to "sign in", new_user_session_path %>

Without the line everything is fine, but when the line is present i've got this error :

No route matches {:controller=>"devise/tops", :action=>"show", :id=>10}

What is the connection with this line oO Why it mix devise and tops ? How can this line trouble the route for devise ? Really weird ... besides all my routes seems fine

new_user_session GET   /users/sign_in(.:format)   devise/sessions#new
top GET                /tops/:id(.:format)        tops#show

回答1:


Please try:

<%= link_to "Official Top", :controller => "/tops", :action => "show", :id => 10 %> 

I think adding the "/" will solve your problem, as it is now searching for the Tops controller within the Devise directory ... with the "/", it will search in the "home controllers" directory instead



来源:https://stackoverflow.com/questions/11452866/weird-route-malfunction-mix-between-devise-and-own-controller

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