1

resources :errors内の異なるフォルダーに異なる URLを持つ 2 つの同じルートがありますroutes.rb

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. 

条件によってこれら 2 つの URL を変更する方法IF。例えば、

location_id が nil の場合、これを表示する必要があります #(url: enr/rds/errors) そうでない場合は(url: enr/locations/:location_id/errors) endを表示する必要があります

そのため、によって異なりますlocation_id。でURLを変更するには、この条件をどこに記述すればよいですかlocation_id。どんな例でも大歓迎です。ありがとう

4

1 に答える 1

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_errors利用可能なパスはこれだけではありenr_lrds_errors ません。7つのデフォルトルート(、、、、、、、)のいずれかを使用するか、indexカスタムルートを追加できますnew。ここをチェックして見てくださいcreateshoweditupdatedestroyrake routes

于 2012-10-24T14:50:16.220 に答える