スラッシュされたスラッグとネストされたルートを追加するのに問題があります。
これらのルートがある場合:
resources :courses do
resources :registrations
end
私はこれらの URL を持っています:
/courses/7
/courses/7/registrations
Course.rb の to_param を変更すると、ルートでスラッグが発生する可能性があります。
def to_param
"#{id}-#{slug}"
end
これにより、次のことがわかります。
/courses/7-title-of-course
/courses/7-title-of-course/registrations
これまでのところすべて順調です。
私が抱えている問題は、このhttp://www.miguelsanmiguel.com/2011/03/17/slug-that-slashを見た後です:
これをネストされたリソースで機能させるにはどうすればよいですか:
Course.rb:
def to_param
"#{id}/#{slug}"
end
Routes.rb
resources :courses, :constraints => { :id => /[0-9]+\/.+/ } do
resources :registrations
end
URL:
/courses/7/title-of-course
/courses/7/title-of-course/registrations
そのように設定すると、コースルートは問題ありませんが、登録ルートが壊れています。
ここにヒントはありますか?