2013-02-14 3 views
0

내 앱에는 티켓이있는 프로젝트가 있습니다. 나는 다음과 같은 방법으로 티켓을 보여줄 수 있기를 원하는 모든 티켓, 프로젝트에 속한뿐만 아니라 티켓을 보여주는중첩 된 경로 만들기

/projects/43/tickets 

이 경로 작동하지만 결과를. 무엇을 바꾸어야합니까?

경로 :

resources :projects do 
    resources :tickets do 
    collection do 
     get "manage" 
    end 
    end 
end 

모델 : 티켓은 다음과 같은 방법으로 프로젝트에 연결되어

class Ticket < ActiveRecord::Base 
    belongs_to :project 
    ... 
end 

class Project < ActiveRecord::Base 
    has_many :tickets, :dependent => :destroy 
    ... 
end 

:

Tickets (table) 
    project_id 
    ...the rest of the fields... 

답변

1

이것은 컨트롤러 로직, 논리를 라우팅하지 않습니다. tickets_controller.rb 이제

def index 
    @project = Project.find(params[:project_id]) 
    @tickets = @project.tickets 
end 

에서 @tickets 현재 프로젝트에 대한 모든 티켓이 포함됩니다.