This has been resolved i will post my answer shortlyRails 4 Маршрут изнутри вложенного маршрута для просмотра страницы по другому вложенному маршруту
Ниже я разместил свои маршруты.rb и все связанные с ними модели/отношения.
То, что я пытаюсь сделать, это вывесить Crud ссылку на PatrolReports (вложенную в PatrolHits) на сайте шоу страницы, вложен в пределах клиентов .. Я получаю эту ошибку:
ActionController::UrlGenerationError at /clients/1/sites/2
No route matches {:action=>"show", :controller=>"patrol_hits/patrol_reports", :id=>"1", :patrol_hit_id=>nil} missing required keys: [:patrol_hit_id]
, когда я Используйте эту ссылку на клиентов/1/сайт/1 Показать страницу
<td><center><%= link_to "View", patrol_hit_patrol_report_path(@patrol_hit, patrol_report) %></center></td>
Здесь находятся все мои маршруты сайт:
# 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
Вот мои модели и отношения:
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
вот мой Rake Маршруты выхода:
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
Пожалуйста, дайте мне знать, если вам потребуются дополнительные детали плохо быть более чем счастливы разместить его и или дать доступ к моему репо
Я на самом деле просто решил эту проблему, я опубликую, как в нескольких. спасибо, что –