다음과 같은 경로를 설정하려고합니다 : acme.com/posts/:category/:status
. :category
및 :status
은 선택 사항입니다. 나는 많은 변화를 썼다, 그러나 아무도 일하지 :레일에서 옵션 매개 변수가있는 경로
resources :posts do
match '(/:category)(/:status)', to: 'posts#index', as: 'filter', on: :collection
end
# Category Links
link_to "Questions", filter_posts_path(:questions)
link_to "Suggestions", filter_posts_path(:suggestions)
# Status Links
link_to "Published", filter_posts_path(params[:category], :published)
link_to "Draft", filter_posts_path(params[:category], :draft)
아이디어는 카테고리에 의해 1) 필터 할 수있다, 2) 필터 상태, 3) 필터에 의해 두 종류 및 상태 경우가 둘 다 사용할 수 있습니다.. 현재 설정에서 내 /posts/new
경로가 손상되어 항상 posts#index
(으)로 리디렉션됩니다.
방금'자원을 사용하지 않는 특별한 이유가 있나요 레이크 : posts' 및 쿼리 문자열에 필터 params를 보냅니 까? (예 :'acme.com/posts? category = foo & status = bar') – rthbound
'/ posts/: category/: status /'또는 적어도/posts/category/: 카테고리/status/: status' – Mohamad