为什么 devise 将 /devise/ 放在每个 link_to 锚点前面?
我刚刚生成了设计的所有视图,并且开始自定义登录屏幕。除了登录页面上生成的所有以“/devise”开头的链接之外,它的效果很好。
- 它为什么要这么做?看起来很奇怪的默认行为
- 如何阻止它向每个 link_to() 添加 /devise?
我的路线文件:
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"}
当我尝试渲染来自设计控制器的页面时收到的错误消息:
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/”添加到我的链接。这根本不是我想要的。
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".
- Why is it doing that? Seems like odd default behaviour
- How do I stop it from adding /devise to every link_to()?
My routes file:
devise_for :users
get "/webpages/:page" => "webpages#show", :as => :show_webpage
root :to => "webpages#index"
My 'rake routes'
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") %>
As you can see above, it's trying to add "devise/" to my link. This is not what I want at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于明白了。
基本上我所做的就是放置“/webpages”而不是“webpages”来告诉rails这些控制器不在“devise”命名空间或父目录下。
这是适当的修复吗?有更简单的解决方案吗?
I figured it out finally.
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?
在较新版本的 Rails 中,您可以执行以下操作:
只需将 _path 附加到执行“rake 路线”时看到的命名路线即可。顺便说一句,将 _url 附加到命名路由将为您提供 URL 字符串。这可能很有用。
伊恩。
In newer versions of Rails you can do:
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.
所有针对 devise 的链接/表单均应以“/devise”开头。请参阅下面由 devise 生成的路由。为什么你想改变这种行为?是不是不起作用?或者您需要/想要定制设备控制器吗?
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?