2011-04-29 93 views
0

我使用的設計對用戶進行認證,並獲得在註冊下面的錯誤和設計和路由錯誤

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

顯然它是由

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

/application.html引起簽署.erb

的設置絕對是基本的,這裏的routes.rb:

get "home/search" 
devise_for :users 
root :to => "home#index" 
+1

快速和骯髒的修復是在控制器名稱,url_for(:controller =>「/ home」,:action =>「search」)之前添加斜槓。另一種方式是使用資源路線。 – synapse 2011-04-29 10:08:23

回答

1

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

使用舊 參數風格時要小心,因爲需要額外的字面 哈希:

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

離開哈希映襯出錯誤 鏈接:

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

如上面鏈接中所述,使用命名資源路由被認爲是「可取的」,這樣如果您的資源路由發生更改,則不必手動更新鏈接。