2012-08-28 67 views
0

我覺得這應該是簡單的,但由於某種原因,我不明白這一點。當用戶在顯示頁面上時,我只想將編輯和刪除操作添加到導航欄中。Rails路由current_page問題在應用程序佈局

我得到的路線錯誤說的編輯操作不會在首頁或新的網頁存在,這裏是我的代碼:

layouts/application.html.haml 

.nav-collapse 
    %ul.nav.pull-right 
     %li= link_to "All Articles", root_path 
     %li= link_to "New Article", new_article_path 
     - if current_page?(@article) 
     %li= link_to 'Edit', edit_article_path 
     %li= link_to 'Delete', { :action => :destroy, :id => @article.id }, :method => :delete, :confirm => 'Are you sure?' 

回答

0

edit頁的鏈接應該有一個id(或某事相對)你想編輯的對象。所以,鏈接幫手應該寫成:

link_to 'Edit', edit_article_path(@article) # or explicitly (@article.id)