2
슬래시 슬래그 및 중첩 된 경로를 추가하는 데 문제가 있습니다. 나는이 노선이있는 경우레일 3 개의 경로와 슬래시 및 중첩 된 리소스
: 나는 Course.rb에 to_param을 변경하는 경우
/courses/7
/courses/7/registrations
, 내가 어떤 굼벵이가 경로에서 일어나는 얻을 수 있습니다 :
resources :courses do
resources :registrations
end
나는이 URL이
def to_param
"#{id}-#{slug}"
end
그러면 다음과 같이 표시됩니다.
/courses/7-title-of-course
/courses/7-title-of-course/registrations
지금까지 모두 좋았습니다.
Course.rb :
def to_param
"#{id}/#{slug}"
end
Routes.rb 나는이 중첩 된 자원으로 작동하도록하려면 어떻게
:
제가하는 데 문제는이 http://www.miguelsanmiguel.com/2011/03/17/slug-that-slash보고 후입니다
resources :courses, :constraints => { :id => /[0-9]+\/.+/ } do
resources :registrations
end
URL :
/courses/7/title-of-course
/courses/7/title-of-course/registrations
코스 루트는 괜찮지 만 등록 경로가 잘못되어있는 것처럼 설정하면됩니다.
여기에 도움말이 있습니까?