开发者

Devise and routing error

开发者 https://www.devze.com 2023-03-02 02:17 出处:网络
I\'m using Devise to authenticate users and getting the following error at registration and sign in pages

I'm using Devise to authenticate users and getting the following error at registration and sign in pages

No route matches {:action=>"search", :controller=>"devise/home"}

Apparently it's caused by

<%= link_to "Search", url_for(:controller => "home", :action => "search")

in layouts/application.html.erb

The setup is absolutely basic, here's routes.rb:

get "home/search"
devise_for 开发者_如何学Go:users
root :to => "home#index"


From http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to:

Be careful when using the older argument style, as an extra literal hash is needed:

link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article"
# => <a href="/articles" class="article" id="news">Articles</a> 

Leaving the hash off gives the wrong link:

link_to "WRONG!", :controller => "articles", :id => "news", :class => "article"
# => <a href="/articles/index/news?class=article">WRONG!</a>

It is considered "preferable" to use named resource routes as described in the link above so that if your resource routes change, you don't have to manually update your links.

0

精彩评论

暂无评论...
验证码 换一张
取 消