2012-06-30 117 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