0

Railsでのルーティングに苦戦中!

これは機能しますhttp://127.0.0.1:3000/locations/1/statisticsが、http://127.0.0.1:3000/locations/機能しません。

私のルートは次のようになります。

resources :locations do
    resources :statistics
end

やるしか http://127.0.0.1:3000/locations/ない

resources locations

しかし、ネストされたルートは機能しません!

どうすれば両方を機能させることができますか?

どうもありがとう。

レーキルートを編集:

     location_statistics GET    /locations/:location_id/statistics(.:format)          statistics#index
                         POST   /locations/:location_id/statistics(.:format)          statistics#create
  new_location_statistic GET    /locations/:location_id/statistics/new(.:format)      statistics#new
 edit_location_statistic GET    /locations/:location_id/statistics/:id/edit(.:format) statistics#edit
      location_statistic GET    /locations/:location_id/statistics/:id(.:format)      statistics#show
                         PUT    /locations/:location_id/statistics/:id(.:format)      statistics#update
                         DELETE /locations/:location_id/statistics/:id(.:format)      statistics#destroy
               locations GET    /locations(.:format)                                  locations#index
                         POST   /locations(.:format)                                  locations#create
            new_location GET    /locations/new(.:format)                              locations#new
           edit_location GET    /locations/:id/edit(.:format)                         locations#edit
                location GET    /locations/:id(.:format)                              locations#show
                         PUT    /locations/:id(.:format)                              locations#update
                         DELETE /locations/:id(.:format)                              locations#destroy
              home_index GET    /home/index(.:format)                                 home#index
                   about        /about(.:format)                                      home#about
                 contact        /contact(.:format)                                    home#contact
                    root        /                                                     home#index

EDIT 2ルート ファイル

match '/about/' => 'home#about'
match '/contact/' => 'home#contact'

resources :locations do
    resources :statistics
end

get "home/index"

編集3

私の実際のエラー:

Routing Error

No route matches {:controller=>"statistics", :location_id=>nil}

私が行くときhttp://127.0.0.1:3000/locations/

4

1 に答える 1

1

どちらかを使用する必要があります

=link_to "Locations", locations_path

また

# get sure @location is not nil
=link_to "Location Statistics", location_statistics_path(@location) 
于 2013-06-26T21:17:04.257 に答える