내 데이터베이스 테이블의 type
열에 따라 URL에 접미어를 추가하고 싶습니다.레일 경로의 사용자 정의 URL
# shop_controller.rb
...
def near
@shop = Shop.find(params[:id])
@type = @shop.type
end
# routes.rb
resources :spots do
member do
get :near
end
end
페이지 내가 현재 app/views/shops/nearby.html.erb
에 있습니다. 생산되는 URL이 현재 :
http://localhost/shops/1/near
대신 서로 다른 유형의 여러 페이지 생성 : nearby_country.html.erb
, nearby_state.html.erb
을 편안하고없는 nearby_city.html.erb
, 내가 유형별로 상점을 필터링하기 위해 URL에 유형을 추가하는 것을 선호 미래에 내가 더 많은 종류가있을 때 있도록 자동으로 표시 할 수 있습니다 :
nearby_country_shop_path
nearby_state_shop_path
nearby_city_shop_path
:
http://localhost/shops/1/near_country
http://localhost/shops/1/near_state
http://localhost/shops/1/near_city
는 또한 싶어처럼 내 메뉴의 사용자 지정 경로를 할 수있을3210
누구든지 몇 가지 힌트를 주실 수 있습니까? 감사!
어쨌든 밑줄을 붙이시겠습니까?'near_country'? – Victor
사실, 이미'show.html.erb'에 대한 국가가 이미 있기 때문에 – Victor