2012-10-24 5 views
1

routes.rb 안에 다른 폴더에있는 다른 URL을 가진 두 개의 동일한 경로 resources :errors가 있습니다.단일 컨트롤러로 두 개의 다른 경로를 리디렉션하는 방법은 무엇입니까?

Routes: 
--------- 

namespace :enr do 
    namespace :locations do #(url: enr/locations/:location_id/errors) 
    resources: errors 
    end 

    namespace :rds do 
    resources :errors #(url: enr/rds/errors) 
    end 
end 

controller: 
------------ 

I have a controller for `enr/rds/errors` only. 

IF 조건에 따라이 두 URL을 변경하는 방법입니다. 예를 들어, location_id가 전무하다

경우 나는

그래서이 변경됩니다 location_id에 따라 달라 (url: enr/locations/:location_id/errors) 끝을 보여줄 필요가이 # (url: enr/rds/errors) 다른 를 표시해야합니다. 어디서 URL을 변경하려면이 조건을 써야합니까 location_id. 모든 예를 들어 주시면 감사하겠습니다. 감사합니다

답변

1
<% if location_id.nil? %> 
    <%= link_to 'nil location_id', enr_locations_errors %> 
<% else %> 
    <%= link_to 'not nil location_id', enr_rds_errors %> 
<% end %> 

enr_locations_errorsenr_lrds_errors 유일한 경로를 사용할 수 없습니다. 7 가지 기본 경로 (, new, create, , edit, update, destroy) 중 하나를 사용하거나 맞춤 경로를 추가 할 수 있습니다. rake routes을 확인하고 here

+0

감사합니다. 컨트롤러 또는보기에이 코드를 추가해야합니까? 감사합니다 –

+0

그것의'html.erb'에 간다 –

+0

대단히 감사합니다! –

관련 문제