2010-11-08 99 views
10

我得到一個錯誤,當我嘗試存取權限的用戶#顯示頁面槽具名的路線(HTTP://本地主機:3000 /資料/)......否則我沒有錯誤,當我嘗試用標準URL(HTTP訪問它://本地主機:3000 /用戶/電流)。如果我耙路線我的路線似乎是正確的,並因爲它與標準URL的作品,我真的不知道爲什麼我沒有得到任何路線配襯錯誤。爲什麼當我甚至不試圖訪問它時,爲什麼試圖找到匹配行爲'摧毀'的路線?沒有路由匹配{:動作=>「消滅」,:控制器=>「用戶」}

Starcast::Application.routes.draw do 

    match "login" => 'user_sessions#new', :as => :login 
    match "logout" => 'user_sessions#destroy', :as => :logout 
    resources :user_sessions 

    match "profile" => 'users#show' 
    resources :users 

    resources :casters 
    resources :casts 
    resources :orders 

    root :to => "home#index" 

end 

錯誤,我得到:

ActionView::Template::Error (No route matches {:action=>"edit", :controller=>"users"}): 
    1: <% title "Welcome #{@user.username}" %> 
    2: 
    3: <%= link_to "Edit your profil", edit_user_path %> 
    4: 
    5: <% has_role? :caster do %> 
    6: <% if @user.caster %> 
    app/views/users/show.html.erb:3:in `_app_views_users_show_html_erb___2116234531537545622_2170017780__3613739707062673465' 
+1

編輯/顯示/銷燬路徑需要一個ID參數...即edit_user_path(current_user.id)...如果你不想那樣做,你需要讓你的路由使用的資源:用戶(而不是資源:用戶),如果你做得不對,這會在後來造成很多頭痛。 – jenjenut233 2010-11-08 22:48:20

+0

韓國社交協會可能你寫它作爲一個答案,所以我可以確認,TKS很多! – plehoux 2010-11-19 22:42:43

回答

24

編輯/顯示/銷燬/更新路徑需要一個ID參數...即edit_user_path(current_user.id)...如果你不想這樣做的,你需要讓你的路由使用的資源:用戶(而非資源:用戶),這將導致大量的頭痛後來在路上,如果你不這樣做是正確的。

相關問題