SO URL과 마찬가지로 URL에 기사 제목을 추가하고 싶습니다. 나는 그러나 나는 그것이 약간 중복 찾아 내 또 다른 질문레일 루트 및 URL 도우미의 중복 줄이기
# routes.rb
match '/articles/:id/:title' => 'articles#show', :as => :article_with_title
# articles/index.html.erb
link_to article.title, article_with_title_path(article, :title => article.title.downcase.gsub(/[^a-z0-9]+/,' ').strip.gsub(/\s+/,'-'))
그것은 작동에 answer에서 다음 설정을 사용하도록 제안했다. 그것을 더 좋게 만드는 방법이 있습니까? 여러 경로를 처리하는 보편적 인 방법은 무엇입니까?
match '/articles/:id/:title' => 'articles#show'
match '/users/:id/:name' => 'users#show'
etc.
비고 :
- 는 현재 다음과 같은 노선들은 잘 작동 : 조건에
/article/:id/:action
,/article/:id/:title
은 그 기사가 제목edit, show, index, etc.
내가 경로를 명시 적으로:id
이 포함되어 있기 때문에friendly_id
가 여기에 불필요한 생각 - 을 가질 수 없습니다 . 내가 보는 것처럼
- 는 SO
/users/:action/:id