2012-04-28 4 views
0

나는 오류정의되지 않은 방법은

undefined method `favorite_relationships_path' 

를 얻을. 나는 코드로, 컨트롤러라는 favorite_relationships_controller.rb와 모델 파일, favorite_relationship.rb이

class FavoriteRelationship < ActiveRecord::Base 
    attr_accessible :lesson_id 
    belongs_to :user 
    belongs_to :lesson 
end 

내 사용자 모델은 있습니다

has_many :favorite_relationships 
    has_many :lessons, :through => :favorite_relationships 

정말 메신저 점점 그 이유를 모르겠어요 오류. 도움을 주시면 감사하겠습니다.

답변

2

컨트롤러, 동작 및보기 정의가 충분하지 않습니다. 컨트롤러/작업에 URL을 연결하려면 config/routes.rb에 정의해야합니다. 라우팅 파일에 resources :favourite_relationships으로 RESTful 리소스를 정의하면 Rails가 *_path*_url 도우미를 생성하게됩니다. 이렇게하면 요청이 앱에 도달 할 수있는 방법이없고 앱이 모델을 기반으로하는 경로를 생성 할 수 없습니다.

귀하의 루트 파일의 모양은 다음과 같습니다

이 편안한 자원에 필요한 전형적인 "CRUD"경로 생성
MyApp::Application.routes.draw do 
    resources :favourite_relationships 
end 

:

favourite_relationships  GET /favourite_relationships(.:format)   {:action=>"index", :controller=>"favourite_relationships"} 
          POST /favourite_relationships(.:format)   {:action=>"create", :controller=>"favourite_relationships"} 
new_favourite_relationship GET /favourite_relationships/new(.:format)  {:action=>"new", :controller=>"favourite_relationships"} 
edit_favourite_relationship GET /favourite_relationships/:id/edit(.:format) {:action=>"edit", :controller=>"favourite_relationships"} 
    favourite_relationship GET /favourite_relationships/:id(.:format)  {:action=>"show", :controller=>"favourite_relationships"} 
          PUT /favourite_relationships/:id(.:format)  {:action=>"update", :controller=>"favourite_relationships"} 
          DELETE /favourite_relationships/:id(.:format)  {:action=>"destroy", :controller=>"favourite_relationships"} 
+0

아, 우리는 거의 동일한 답변을 동시에 작성했습니다! :) – tiredpixel

+0

오, 내가 완전히 잊어 버렸어. 나는 라우트 파일에있는 url에 대해서만 생각하고 있었다. 즉, localhost : 3000/lessons/favorites과 같은 것 아래에있는 것처럼 생각했다. 고마워요! – Sasha

2

레일 경로에 대한 _path_url 도우미가 있습니다를, 이들은 config/routes.rb에 설정되어 있습니다. FavouriteRelationshipController에 대한 경로를 정의했는지 확인해야합니다. 뭔가 같은 :

resources :favourite_relationships 

당신은 rake routes 명령을 사용하여 응용 프로그램에 대해 정의 된 경로를 확인할 수 있습니다.

라우팅에 대한 자세한 내용은 Rails Routing from the Outside In 가이드를 참조하십시오.

+0

오, 내가 완전히 잊어 버렸습니다. 나는 라우트 파일에있는 url에 대해서만 생각하고 있었다. 즉, localhost : 3000/lessons/favorites과 같은 것 아래에있는 것처럼 생각했다. 고마워요! – Sasha

관련 문제