2012-05-11 7 views
0

조직에 대한 새 이벤트를 만들 수있는 양식이 있습니다. 라우팅은 다음과 같습니다레일 3 예상대로 작동하지 않는 경로

resource :organisations do 
    resource :events 
end 

나는 등 다시 이벤트 컨트롤러의 show 액션에 성공 I 경로에 이벤트를 편집 할 때 : 나는 이벤트를 만들 때

def update 
    @organisation = current_user.organisations.find(params[:organisation_id]) 
    @event = @organisation.events.find(params[:id]) 
    if @event.update_attributes(params[:event]) 
     # Handle a successful update. 
     flash[:success] = "Event updated" 
     redirect_to organisation_event_path 
    else 
     render 'edit' 
    end 
end 

, 나는 또한 원하는 No route matches {:action=>"show", :controller=>"events"}

:

def create 
    @organisation = current_user.organisations.find(params[:organisation_id]) 
    @event = @organisation.events.create(params[:event]) 
    if @event.save 
     flash[:success] = "Event added!" 
     redirect_to organisation_event_path 
    else 
     render 'new' 
    end 
end 

그러나, 이것은 다음과 같은 오류가 발생 다음과 같이 이벤트로 리디렉션 구현, 행동을 보여

URI가 이벤트 ID/이름을 가지고 있지 않기 때문에 알아낼 수 있습니다. 경로 생성에 대한 이해가 부족한 것이지만 원하는 결과를 얻으려면 어떻게해야합니까?

+0

을 당신이 조직이 조직 ID로 인식하므로 이벤트가 조직에서 생성되기 때문에 redirect_to의 organisation_event_path에 조직 ID를 전달할 필요가 있다고 생각합니다. –

답변

0

첫 번째 리디렉션이 작동 한 이유는 확실하지 않지만 organisation_event_path는 두 개의 리소스 (조직 및 이벤트)의 ID에서 경로를 생성하기 때문에 두 개의 인수가 필요합니다. 그래서, 당신은 다음과 같이 호출한다 :

organisation_event_path(@organization, @event) 
관련 문제