为什么要在每个link_to的前面设置put / devise /? [英] Why does devise put /devise/ in front of every link_to anchor?

查看:129
本文介绍了为什么要在每个link_to的前面设置put / devise /?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚生成了所有的设计视图,我开始自定义登录屏幕。除了所有在登录页面上生成的链接以/ devise开头,它的效果非常好。

I just generated all the views for devise, and I'm starting to customize the login screen. It works great except for all the links that are generated on the sign in page start with "/devise".


  1. 为什么这样做?看起来像奇怪的默认行为

  2. 如何阻止它添加/设计每个link_to()?

我的路线文件:

devise_for :users

get "/webpages/:page" => "webpages#show", :as => :show_webpage

root :to => "webpages#index"

我的'rake路线'

        new_user_session GET    /users/sign_in(.:format)       {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.: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/sign_up(.: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"}
            show_webpage GET    /webpages/:page(.:format)      {:controller=>"webpages", :action=>"show"}
                    root        /(.:format)                    {:controller=>"webpages", :action=>"index"}

当我尝试并渲染来自设计控制器的页面时,我得到的错误消息:

The error message I get when I try and render a page that comes from the devise controller:

ActionController::RoutingError in Devise/sessions#new

Showing /home/egervari/Projects/training/app/views/layouts/application.html.erb where line #21 raised:

No route matches {:controller=>"devise/webpages", :action=>"show", :page=>"tour"}

Extracted source (around line #21):

18:           </a>
19:         </li>
20:         <li>
21:           <%= link_to("Tour", :controller => "webpages", :action => "show", :page => "tour") %>
22:         </li>
23:         <li>
24:           <%= link_to("Why Use Us?", :controller => "webpages", :action => "show", :page => "why") %>

如上所示,它试图在我的链接中添加devise /。这不是我想要的。

As you can see above, it's trying to add "devise/" to my link. This is not what I want at all.

推荐答案

在较新版本的Rails中,您可以执行以下操作:

In newer versions of Rails you can do:

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

您只需将_path附加到您在执行耙子路线时看到的命名路径上。将_url附加到指定的路由将为您提供URL字符串BTW。这可以是有用的。

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。

这篇关于为什么要在每个link_to的前面设置put / devise /?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆