Why does devise put /devise/ in front of every link_to anchor?

旧城冷巷雨未停 提交于 2019-12-07 00:22:32

In newer versions of Rails you can do:

<%= link_to "Privacy Policy", show_webpage_path(:page => 'privacy') %>

You just append a _path onto the named route that you see when you do a 'rake routes'. Appending _url to the named route will give you the URL string, BTW. Which can be useful.

ian.

I figured it out finally.

      <li><%= link_to("Terms and Use", :controller => "/webpages", :action => "show", :page => "terms") %> |</li>
      <li><%= link_to("Privacy Policy", :controller => "/webpages", :action => "show", :page => "privacy") %> |</li>

Basically what I did was put "/webpages" instead of "webpages" to tell rails that these controllers were not under the "devise" namespace or parent directory.

Is this the appropriate fix? Is there a simpler solution?

All links/forms targeted to devise are expected to start with "/devise". See the routes generated by devise below. Why do you want change this behavior? Is it not working? Or do you need/want to customize the devise controllers?

          new_user_session GET    /users/login(.:format)                                           {:action=>"new", :controller=>"devise/sessions"}
              user_session POST   /users/login(.:format)                                           {:action=>"create", :controller=>"devise/sessions"}
      destroy_user_session GET    /users/sign_out(.:format)                                        {:action=>"destroy", :controller=>"devise/sessions"}
             user_password POST   /users/password(.:format)                                        {:action=>"create", :controller=>"devise/passwords"}
         new_user_password GET    /users/password/new(.:format)                                    {:action=>"new", :controller=>"devise/passwords"}
        edit_user_password GET    /users/password/edit(.:format)                                   {:action=>"edit", :controller=>"devise/passwords"}
                           PUT    /users/password(.:format)                                        {:action=>"update", :controller=>"devise/passwords"}
  cancel_user_registration GET    /users/cancel(.:format)                                          {:action=>"cancel", :controller=>"devise/registrations"}
         user_registration POST   /users(.:format)                                                 {:action=>"create", :controller=>"devise/registrations"}
     new_user_registration GET    /users/register(.:format)                                        {:action=>"new", :controller=>"devise/registrations"}
    edit_user_registration GET    /users/edit(.:format)                                            {:action=>"edit", :controller=>"devise/registrations"}
                           PUT    /users(.:format)                                                 {:action=>"update", :controller=>"devise/registrations"}
                           DELETE /users(.:format)                                                 {:action=>"destroy", :controller=>"devise/registrations"}
         user_confirmation POST   /users/confirmation(.:format)                                    {:action=>"create", :controller=>"devise/confirmations"}
     new_user_confirmation GET    /users/confirmation/new(.:format)                                {:action=>"new", :controller=>"devise/confirmations"}
                           GET    /users/confirmation(.:format)                                    {:action=>"show", :controller=>"devise/confirmations"}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!