레일을 사용하여 여러 경로를 하나의 컨트롤러 동작으로 변환하는 더 깨끗하고 우아한 방법이 있는지 궁금합니다.ElegantRails - 하나의 컨트롤러에 대한 다중 경로 동작
#routes.rb
get 'suggestions/proxy', to: 'suggestions#index'
get 'suggestions/aimee', to: 'suggestions#index'
get 'suggestions/arty', to: 'suggestions#index'
...
#suggestion_controller.rb
case request.env['PATH_INFO']
when '/suggestions/proxy'
@suggestions = Suggestion.all.where(:suggestion_type => 'proxy')
when '/suggestions/aimee'
@suggestions = Suggestion.all.where(:suggestion_type => 'aimee')
when '/suggestions/arty'
@suggestions = Suggestion.all.where(:suggestion_type => 'arty')
...
else
@suggestions = Suggestion.all
end
나는이이 post을 읽었습니다,하지만 난 그것을 사용하는 경우 오류를 받고 있었다.
여기에 할 일이 많지 않으면 큰 문제는 아닙니다. 나는 비디오 게임에 웹 사이트를 구축하고 있는데, 나는 더러운 폭탄라고 불리며 총 19 개의 용병이 열거되어 있어야하기 때문에 더 깨끗한 방법을 원했기 때문이다.
감사합니다.
[와일드 카드 세그먼트] (http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments)를 읽어야합니다. 그것은 당신이하고있는 일을위한 것입니다. – jvillian