Rails 4从嵌套路由中路由以查看另一个嵌套路由上的页面

时间:2016-09-28 22:24:02

标签: ruby-on-rails ruby-on-rails-4 routing

  

此问题已经解决,我将尽快发布我的回答

下面我发布了我的routes.rb以及与之关联的所有模型/关系。

我想要做的是将crud链接发布到嵌套在客户端的网站展示页面上的PatrolReports(嵌套到PatrolHits)..我不断收到此错误:

  # Nests Sites To Clients
  resources :clients, controller: 'clients' do
    resources :sites, controller: 'clients/sites', except: [:index]
  end

  # Nests PatrolHit To PatrolRoutes
  resources :patrol_routes, controller: 'patrol_routes' do
    resources :patrol_hits, controller: 'patrol_routes/patrol_hits', except: [:index]
  end

  # Nests PatrolReport to PatrolHits
  resources :patrol_hits, controller: 'patrol_routes/patrol_hits', except: [:index] do
    resources :patrol_reports, controller: 'patrol_hits/patrol_reports', except: [:index]
  end

当我在clients / 1 / site / 1 Show Page

上使用此链接时
class Client < ApplicationRecord
  has_many :sites, dependent: :destroy
end

class Site < ApplicationRecord
  belongs_to :client
  has_many :patrol_hits
  has_many :patrol_reports, dependent: :destroy
end

class PatrolRoute < ApplicationRecord
  has_many :patrol_hits, dependent: :destroy
end

class PatrolHit < ApplicationRecord
  belongs_to :site
  belongs_to :patrol_route
  has_many :patrol_reports, dependent: :destroy
end

class PatrolReport < ApplicationRecord
  belongs_to :patrol_hit
  belongs_to :site
  belongs_to :user
end

以下是我的所有网站路线:

                       Prefix Verb   URI Pattern                                                    Controller#Action

                 client_sites POST   /clients/:client_id/sites(.:format)                            clients/sites#create
              new_client_site GET    /clients/:client_id/sites/new(.:format)                        clients/sites#new
             edit_client_site GET    /clients/:client_id/sites/:id/edit(.:format)                   clients/sites#edit
                  client_site GET    /clients/:client_id/sites/:id(.:format)                        clients/sites#show
                              PATCH  /clients/:client_id/sites/:id(.:format)                        clients/sites#update
                              PUT    /clients/:client_id/sites/:id(.:format)                        clients/sites#update
                              DELETE /clients/:client_id/sites/:id(.:format)                        clients/sites#destroy
                      clients GET    /clients(.:format)                                             clients#index
                              POST   /clients(.:format)                                             clients#create
                   new_client GET    /clients/new(.:format)                                         clients#new
                  edit_client GET    /clients/:id/edit(.:format)                                    clients#edit
                       client GET    /clients/:id(.:format)                                         clients#show
                              PATCH  /clients/:id(.:format)                                         clients#update
                              PUT    /clients/:id(.:format)                                         clients#update
                              DELETE /clients/:id(.:format)                                         clients#destroy
     patrol_route_patrol_hits POST   /patrol_routes/:patrol_route_id/patrol_hits(.:format)          patrol_routes/patrol_hits#create
  new_patrol_route_patrol_hit GET    /patrol_routes/:patrol_route_id/patrol_hits/new(.:format)      patrol_routes/patrol_hits#new
 edit_patrol_route_patrol_hit GET    /patrol_routes/:patrol_route_id/patrol_hits/:id/edit(.:format) patrol_routes/patrol_hits#edit
      patrol_route_patrol_hit GET    /patrol_routes/:patrol_route_id/patrol_hits/:id(.:format)      patrol_routes/patrol_hits#show
                              PATCH  /patrol_routes/:patrol_route_id/patrol_hits/:id(.:format)      patrol_routes/patrol_hits#update
                              PUT    /patrol_routes/:patrol_route_id/patrol_hits/:id(.:format)      patrol_routes/patrol_hits#update
                              DELETE /patrol_routes/:patrol_route_id/patrol_hits/:id(.:format)      patrol_routes/patrol_hits#destroy
                patrol_routes GET    /patrol_routes(.:format)                                       patrol_routes#index
                              POST   /patrol_routes(.:format)                                       patrol_routes#create
             new_patrol_route GET    /patrol_routes/new(.:format)                                   patrol_routes#new
            edit_patrol_route GET    /patrol_routes/:id/edit(.:format)                              patrol_routes#edit
                 patrol_route GET    /patrol_routes/:id(.:format)                                   patrol_routes#show
                              PATCH  /patrol_routes/:id(.:format)                                   patrol_routes#update
                              PUT    /patrol_routes/:id(.:format)                                   patrol_routes#update
                              DELETE /patrol_routes/:id(.:format)                                   patrol_routes#destroy
    patrol_hit_patrol_reports POST   /patrol_hits/:patrol_hit_id/patrol_reports(.:format)           patrol_hits/patrol_reports#create
 new_patrol_hit_patrol_report GET    /patrol_hits/:patrol_hit_id/patrol_reports/new(.:format)       patrol_hits/patrol_reports#new
edit_patrol_hit_patrol_report GET    /patrol_hits/:patrol_hit_id/patrol_reports/:id/edit(.:format)  patrol_hits/patrol_reports#edit
     patrol_hit_patrol_report GET    /patrol_hits/:patrol_hit_id/patrol_reports/:id(.:format)       patrol_hits/patrol_reports#show
                              PATCH  /patrol_hits/:patrol_hit_id/patrol_reports/:id(.:format)       patrol_hits/patrol_reports#update
                              PUT    /patrol_hits/:patrol_hit_id/patrol_reports/:id(.:format)       patrol_hits/patrol_reports#update
                              DELETE /patrol_hits/:patrol_hit_id/patrol_reports/:id(.:format)       patrol_hits/patrol_reports#destroy
                  patrol_hits POST   /patrol_hits(.:format)                                         patrol_routes/patrol_hits#create
               new_patrol_hit GET    /patrol_hits/new(.:format)                                     patrol_routes/patrol_hits#new
              edit_patrol_hit GET    /patrol_hits/:id/edit(.:format)                                patrol_routes/patrol_hits#edit
                   patrol_hit GET    /patrol_hits/:id(.:format)                                     patrol_routes/patrol_hits#show
                              PATCH  /patrol_hits/:id(.:format)                                     patrol_routes/patrol_hits#update
                              PUT    /patrol_hits/:id(.:format)                                     patrol_routes/patrol_hits#update
                              DELETE /patrol_hits/:id(.:format)                                     patrol_routes/patrol_hits#destroy
                  static_home GET    /static/home(.:format)                                         static#home
                 static_about GET    /static/about(.:format)                                        static#about
                  static_help GET    /static/help(.:format)                                         static#help
       static_feature_request GET    /static/feature_request(.:format)                              static#feature_request

以下是我的模特和关系:

{{1}}

这是我的Rake Routes输出:

{{1}}

如果您需要任何进一步的详细信息,请告诉我,我们非常乐意发布该信息或访问我的回购

1 个答案:

答案 0 :(得分:1)

  

patrol_hit_patrol_report_path(@patrol_hit, patrol_report)

看起来patrol_report是零。