2012-06-30 63 views
0

我想以這樣的URL來訪問我的檢查站#指數法: http://localhost:3000/lessons/introductions/checkpoints/導軌路由錯誤?

但我得到這個錯誤:因爲在我的「耙路線」

No route matches {:action=>"show", :controller=>"checkpoints", :lesson_id=>#<Checkpoint id: 1, checkpoint: "Definition of Monetary Policy", url: "http://www.youtube.com/watch?v=HX3wOWN9-sM", objective: "Define monetary policy", description: "Welcome to this series of lectures on monetary poli...", question: "What is the definition of monetary policy?", hint: "It is the deliberate manipulation of something OR s...", answer: "-", lesson_id: 8, created_at: "2012-06-29 07:21:47", updated_at: "2012-06-30 08:24:15", slug: "definition-of-monetary-policy">}

這不應該是這樣的:

 lesson_checkpoints GET /lessons/:lesson_id/checkpoints(.:format)   checkpoints#index 
         POST /lessons/:lesson_id/checkpoints(.:format)   checkpoints#create 
    new_lesson_checkpoint GET /lessons/:lesson_id/checkpoints/new(.:format)  checkpoints#new 
    edit_lesson_checkpoint GET /lessons/:lesson_id/checkpoints/:id/edit(.:format) checkpoints#edit 
     lesson_checkpoint GET /lessons/:lesson_id/checkpoints/:id(.:format)  checkpoints#show 
         PUT /lessons/:lesson_id/checkpoints/:id(.:format)  checkpoints#update 
         DELETE /lessons/:lesson_id/checkpoints/:id(.:format)  checkpoints#destroy` 

不是加載#index操作而不是#show操作?有誰知道這個錯誤的可能原因?

這是我的routes.rb看起來像:

resources :lessons do 
    resources :checkpoints 
end 

resources :lessons 

resources :topics do 
    resources :lessons 
end 

#Devise Routes 
devise_for :users 


resources :subjects do 
    resources :topics 
end 
+0

聽起來更像是某個視圖中的某個東西試圖鏈接到一個不存在的動作/控制器/參數組合。 –

回答

0

我發現了問題:我的friendly_id是正確的。錯誤在我看來。我已經定義了兩次資源,所以我可以訪問localhost/lessons/blahblah的url。這對我有用。我的視圖文件需要編輯(從默認的未嵌套的文件),一旦它被糾正,一切都再次順利進行。

0

我想你沒有爲「介紹」中提到的路線。

resources :lessons do 
    resources :introductions 
end 

resources :introductions do 
    resources :checkpoints 
end 
+0

我已經使用這個rails應用程序的friendly_id。 我課的名字是「介紹」。導航到http:// localhost:3000/lessons/8/checkpoints /會導致相同的錯誤。 –

0

我看到兩個問題:

  1. 我認爲有一些問題與建立friendly_id您的經驗模型。 您的friendly_id設置將檢查點的對象作爲您課程的友好標識,而不是課程的標題,這是您希望從給定的URL獲得的標題。

  2. 您的路線聲明不正確。你宣佈資源「課程」兩次。

resources :lessons do 
    resources :checkpoints 
end 
resources :lessons 

您可以檢查您friendly_id的正確性控制檯:

lesson = Lesson.create(name: 'introduction') 
lesson.friendly_id #=> should output 'introduction' 
+0

我發現問題: 我的friendly_id是正確的。錯誤在我看來。 我已經定義了兩次資源,所以我可以訪問localhost/lessons/blahblah的url。這對我有用。 我的視圖文件需要編輯(從默認的未嵌套的一個),一旦它被糾正,一切都再次順利進行。 –

+0

課程的第一個宣言將創建像這樣的路線localhost/lessons/blahblah,就像您的第二個聲明一樣,根本不需要第二個聲明。你可以通過刪除它來檢查它。 – Salil